| 比赛 |
期末考试2 |
评测结果 |
AAAAAATAAA |
| 题目名称 |
物流 |
最终得分 |
90 |
| 用户昵称 |
2_16鸡扒拌面 |
运行时间 |
3.926 s |
| 代码语言 |
C++ |
内存使用 |
10.86 MiB |
| 提交时间 |
2026-02-10 09:52:19 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define MAXN 1000005
#define lowbit(x) ((~(x)+1)&x)
int n, m;
LL tr1[MAXN],tr2[MAXN];
char ch, sig;
template <typename _tp>
inline void rd(_tp &num)
{
num = 0, sig = 1, ch = getchar();
while(ch < '0' || ch > '9') {
if(ch == '-') sig = -1;
ch = getchar();
}
while(ch>='0'&&ch<='9'){
num=num*10+ch-'0';
ch=getchar();
}
num *= sig;
}
inline void tradd(LL *tr,int p,int num){while(p <= m + 1) tr[p] += num, p += lowbit(p);}
inline LL trqry(LL *tr,int p){
LL sum=0;
while(p) sum+=tr[p],p^=lowbit(p);
return sum;
}
char op[MAXN];
int t1[MAXN], t2[MAXN], ts[MAXN];
int bs(int num){
int l=1,r=m+1,mid;
while(l<r){
mid=(l+r)>>1;
if(ts[mid]<num) l=mid+1;
else if(ts[mid]>num) r=mid-1;
else return mid;
}
return l;
}
int arr[MAXN];
int main()
{
freopen("logistics.in","r",stdin);
freopen("logistics.out","w",stdout);
cin>>n>>m;
for(int i=1; i <= m; ++i) {
while(ch!='U'&&ch!='Z') ch=getchar();
op[i]=ch;
rd(t1[i]),rd(t2[i]);
ts[i]=t2[i];
}
ts[m+1]=0;
std::sort(ts+1,ts+m+2);
for(int i = 1; i <= m + 1; ++i) arr[i] = 1;
int tbs=bs(0); LL tmp;
tradd(tr2, tbs, n);
tradd(tr2, tbs + 1, -n);
for(int i = 1; i <= m; ++i)
if(op[i] == 'U'){
tbs = bs(t2[i]);
tradd(tr1, arr[t1[i]], -ts[arr[t1[i]]]);
tradd(tr1, tbs, ts[tbs]);
tradd(tr2, arr[t1[i]] + 1, 1);
tradd(tr2, tbs + 1, -1);
arr[t1[i]] = tbs;
}
else{
tbs=bs(t2[i]);
tmp=(t1[i]-trqry(tr2,tbs))*t2[i];
printf("%s\n",trqry(tr1,tbs-1)>=tmp?"TAK":"NIE");
}
return 0;
}