| 比赛 |
期末考试2 |
评测结果 |
AAAAAAAAAA |
| 题目名称 |
物流 |
最终得分 |
100 |
| 用户昵称 |
zhyn |
运行时间 |
4.142 s |
| 代码语言 |
C++ |
内存使用 |
33.95 MiB |
| 提交时间 |
2026-02-10 09:39:27 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 1000005
#define inf 1000000001
int n,m;
int root,tot=0;
int ls[maxn*20],rs[maxn*20];
int cnt[maxn*20];
ll sum[maxn*20];
ll w[maxn];
ll ans=0;
struct node{
int x;
ll y;
};
void pushup(int u){
cnt[u]=cnt[ls[u]]+cnt[rs[u]];
sum[u]=sum[ls[u]]+sum[rs[u]];
}
void update(int &u,int l,int r,ll v,int k){
if(!u){
u=++tot;
}
if(l==r){
cnt[u]+=k;
sum[u]+=k*v;
return;
}
int mid=(l+r)/2;
if(v<=mid){
update(ls[u],l,mid,v,k);
}
else{
update(rs[u],mid+1,r,v,k);
}
pushup(u);
}
node query(int u,int l,int r,ll s){
if(!u){
return{0,0};
}
if(r<=s){
return{0,0};
}
if(l>s){
return{cnt[u],sum[u]};
}
int mid=(l+r)/2;
node ql=query(ls[u],l,mid,s);
node qr=query(rs[u],mid+1,r,s);
int x=ql.x+qr.x;
ll y=ql.y+qr.y;
return{x,y};
}
int main(){
freopen("logistics.in","r",stdin);
freopen("logistics.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
while(m--){
char op;
int k,c;
ll a,s;
cin>>op;
if(op=='U'){
cin>>k>>a;
ll t=w[k];
ans+=a-t;
update(root,0,inf,t,-1);
update(root,0,inf,a,1);
w[k]=a;
}
else{
cin>>c>>s;
node p=query(root,0,inf,s);
int x=p.x;
ll y=p.y;
ll d=ans-(y-s*x);
if(d>=(ll)s*c){
cout<<"TAK\n";
}
else{
cout<<"NIE\n";
}
}
}
return 0;
}