0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

4378. [POI2015] Logistyka

https://hydro.ac/d/bzoj/record/62541fb017cd4d0a41752301
This commit is contained in:
Baoshuo Ren 2022-04-11 20:32:10 +08:00
parent d8a54b4f5a
commit d2719a853e
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

62
BZOJ/4378/4378.cpp Normal file
View File

@ -0,0 +1,62 @@
#include <algorithm>
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2e6 + 5;
int n, m, x[N], y[N], a[N], p, nums[N];
char op[N];
long long c1[N], c2[N];
inline int lowbit(int x) {
return x & -x;
}
void add(long long *c, int x, int y) {
for (; x <= n + m; x += lowbit(x)) c[x] += y;
}
long long sum(long long *c, int x) {
long long ans = 0;
for (; x; x -= lowbit(x)) ans += c[x];
return ans;
}
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> op[i] >> x[i] >> y[i];
nums[++p] = y[i];
}
std::sort(nums + 1, nums + 1 + p);
p = std::unique(nums + 1, nums + 1 + p) - nums - 1;
for (int i = 1, k; i <= m; i++) {
y[i] = std::lower_bound(nums + 1, nums + 1 + p, y[i]) - nums;
if (op[i] == 'U') {
if (k = a[x[i]]) {
add(c1, k, -1);
add(c2, k, -nums[k]);
}
k = a[x[i]] = y[i];
add(c1, k, 1);
add(c2, k, nums[k]);
} else { // op[i] == 'Z'
int c = sum(c1, p) - sum(c1, y[i] - 1);
long long s = sum(c2, y[i] - 1);
cout << (s >= 1ll * (x[i] - c) * nums[y[i]] ? "TAK" : "NIE") << endl;
}
}
return 0;
}