| 比赛 |
期末考试2 |
评测结果 |
AAAAAAAAAA |
| 题目名称 |
物流 |
最终得分 |
100 |
| 用户昵称 |
RpUtl |
运行时间 |
2.998 s |
| 代码语言 |
C++ |
内存使用 |
41.14 MiB |
| 提交时间 |
2026-02-10 11:39:29 |
显示代码纯文本
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
const int N=1e6+10;
const int V=1e9;
int n,m,cnt,rt,a[N];
struct node{
int lc,rc;
int cnt;
ll sum;
}tr[N*32];
void pushup(int p){
tr[p].cnt=tr[tr[p].lc].cnt+tr[tr[p].rc].cnt;
tr[p].sum=tr[tr[p].lc].sum+tr[tr[p].rc].sum;
}
void upd(int &p,int l,int r,int x,int v){
if(!p)p=++cnt;
if(l==r){
tr[p].cnt+=v,tr[p].sum+=v*l;
}else{
int mid=(l+r)>>1;
if(x<=mid)upd(tr[p].lc,l,mid,x,v);
if(x>mid)upd(tr[p].rc,mid+1,r,x,v);
pushup(p);
}
}
int askcnt(int p,int l,int r,int L,int R){
if(!p)return 0;
if(L<=l&&r<=R)return tr[p].cnt;
int mid=(l+r)>>1,cnt=0;
if(L<=mid)cnt+=askcnt(tr[p].lc,l,mid,L,R);
if(R>mid)cnt+=askcnt(tr[p].rc,mid+1,r,L,R);
return cnt;
}
int asksum(int p,int l,int r,int L,int R){
if(!p)return 0;
if(L<=l&&r<=R)return tr[p].sum;
int mid=(l+r)>>1;ll cnt=0;
if(L<=mid)cnt+=asksum(tr[p].lc,l,mid,L,R);
if(R>mid)cnt+=asksum(tr[p].rc,mid+1,r,L,R);
return cnt;
}
const int MAXSIZE=(1<<22);
char buf[1<<22],*p1,*p2;
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,MAXSIZE,stdin),p1==p2)?EOF:*p1++)
inline void read(int &a){
int x=0,f=1;char ch=gc();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
while(isdigit(ch))x=(x<<3)+(x<<1)+ch-48,ch=gc();
return a=x*f,void();
}
int main(){
freopen("logistics.in","r",stdin);
freopen("logistics.out","w",stdout);
read(n),read(m);
upd(rt,0,V,0,n);
int x,y;
char o;
while(m--){
o=gc();
read(x),read(y);
if(o=='U'){
upd(rt,0,V,a[x],-1);
a[x]=y;
upd(rt,0,V,a[x],1);
}else{
ll val=asksum(rt,0,V,0,y)+1ll*(n-askcnt(rt,0,V,0,y))*y;
if(val>=1ll*x*y){
printf("TAK\n");
}else{
printf("NIE\n");
}
}
}
return 0;
}