题目链接:传送门
号脚的人可以穿大小的鞋
设为号脚的人的数量
假设选择区间
就要满足
把提出来
即
维护一个全局最大子段和就好了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <ctime>
#include <set>
#include <vector>
#include <iomanip>
#define
#define
using namespace std;
typedef long long ll;
struct node {
ll l, r, w, lc, rc, c;
}tree[A];
ll n, m, kk, d, a, b, c;
void up(ll k) {
tree[k].w = tree[k << 1].w + tree[k << 1 | 1].w;
tree[k].lc = max(tree[k << 1].lc, tree[k << 1].w + tree[k << 1 | 1].lc);
tree[k].rc = max(tree[k << 1 | 1].rc, tree[k << 1 | 1].w + tree[k << 1].rc);
tree[k].c = max(max(tree[k << 1].c, tree[k << 1 | 1].c), tree[k << 1].rc + tree[k << 1 | 1].lc);
}
void build(ll k, ll l, ll r) {
tree[k].l = l;
tree[k].r = r;
if (l == r) {
tree[k].w += -kk;
tree[k].lc = tree[k].rc = tree[k].c = tree[k].w;
return;
}
ll m = (l + r) >> 1;
build(k << 1, l, m);
build(k << 1 | 1, m + 1, r);
up(k);
}
void change(ll k) {
if (tree[k].l == tree[k].r) {
tree[k].w += c;
tree[k].lc = tree[k].rc = tree[k].c = tree[k].w;
return;
}
ll m = (tree[k].l + tree[k].r) >> 1;
if (a <= m) change(k << 1);
else change(k << 1 | 1);
up(k);
}
int main(int argc, char *argv[]) {
scanf("%lld%lld%lld%lld", &n, &m, &kk, &d);
build(1, 1, n);
while (m--) {
scanf("%lld%lld", &a, &c);
change(1);
if (tree[1].c <= d * kk) puts("TAK");
else puts("NIE");
}
}