| 比赛 |
期末考试2 |
评测结果 |
AAAAAAAAAA |
| 题目名称 |
物流 |
最终得分 |
100 |
| 用户昵称 |
xuyuqing |
运行时间 |
2.718 s |
| 代码语言 |
C++ |
内存使用 |
16.07 MiB |
| 提交时间 |
2026-02-10 10:11:22 |
显示代码纯文本
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
const int N = 1919810;
int n;
int m;
vector<tuple<char, int, int>> ops;
vector<int> nums;
unordered_map<int, int> tran;
struct bit {
long long tree[N];
int lowbit (int id) {
return id & (-id);
}
void add (int id, long long x) {
for (; id <= nums.size(); id += lowbit (id)) {
tree[id] += x;
}
}
long long query (int id) {
long long res = 0;
for (; id; id -= lowbit (id)) {
res += tree[id];
}
return res;
}
};
int arr[N];
bit cc;
bit sum;
long long all;
int main () {
#ifndef ONLINE_JUDGE
freopen ("logistics.in", "r", stdin);
freopen ("logistics.out", "w", stdout);
#endif
scanf ("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
char ch;
int x, y;
scanf ("%s%d%d", &ch, &x, &y);
ops.emplace_back(ch, x, y);
nums.emplace_back(y);
}
nums.emplace_back(0);
sort (nums.begin(), nums.end());
nums.erase(unique (nums.begin(), nums.end()), nums.end());
for (int i = 0; i < nums.size(); i++) {
tran[nums[i]] = i + 1;
}
cc.add(tran[0], n);
for (auto [op, x, y] : ops) {
if (op == 'U') {
cc.add(tran[arr[x]], -1);
sum.add(tran[arr[x]], -arr[x]);
all -= arr[x];
arr[x] = y;
cc.add(tran[arr[x]], 1);
sum.add(tran[arr[x]], arr[x]);
all += arr[x];
}
else {
long long ccl = cc.query(tran[y] - 1);
long long ccr = n - ccl;
long long suml = sum.query(tran[y] - 1);
long long sumr = all - suml;
if (suml >= y * (x - ccr)) {
printf ("TAK\n");
}
else {
printf ("NIE\n");
}
}
}
return 0;
}