QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#27498 | #2808. Gardening | reiofa | 0 | 6ms | 18464kb | C++ | 3.5kb | 2022-04-09 17:07:32 | 2022-04-29 06:14:16 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define qk(w) ((w)-1)/kc+1
using namespace std;
const int N = 2e5+11;
const ll inf = 1e18;
int n, m, kc;
ll a[N], b[N], a1[N], id[N];
struct ques {
int l, r, k, id;
ll ans;
} q[N];
bool cmp1(ques p1, ques p2) {
if(qk(p1.l) != qk(p2.l)) return p1.l < p2.l;
return p1.r < p2.r;
}
bool cmp2(ques p1, ques p2) {
return p1.id < p2.id;
}
int ct[N], tot;
struct sgt {
ll mx[N*4], tag[N*4];
int siz[N*4];
void pushdown(int k) {
ll s = tag[k]; tag[k] = 0;
tag[k<<1] += s; tag[k<<1|1] += s;
mx[k<<1] += s; mx[k<<1|1] += s;
}
void modify(int k, int l, int r, int L, int R, ll s) {
if(l >= L && r <= R) {
mx[k] += s;
tag[k] += s;
return;
}
pushdown(k);
int mid = (l + r) >> 1;
if (L <= mid) modify(k<<1, l, mid, L, R, s);
if (R > mid) modify(k<<1|1, mid+1, r, L, R, s);
mx[k] = max(mx[k<<1], mx[k<<1|1]);
}
void add(int k, int l, int r, int w, int s) {
if(l == r) {
siz[k] += s;
if(ct[l] == 1 && s == 1) mx[k] += inf;
else if(ct[l] == 0 && s == -1) mx[k] -= inf;
return;
}
pushdown(k);
int mid = (l + r) >> 1;
if (w <= mid) add(k<<1, l, mid, w, s);
else add(k<<1|1, mid+1, r, w, s);
siz[k] = siz[k<<1] + siz[k<<1|1];
mx[k] = max(mx[k<<1], mx[k<<1|1]);
}
ll query(int k, int l, int r, int L, int R) {
if(L > R) return -inf*2;
if(l >= L && r <= R) return mx[k];
pushdown(k);
int mid = (l + r) >> 1; ll ret = -inf*2;
if (L <= mid) ret = max(ret, query(k<<1, l, mid, L, R));
if (R > mid) ret = max(ret, query(k<<1|1, mid+1, r, L, R));
return ret;
}
int find(int k, int l, int r, int s) {
if (l == r) return l;
int mid = (l+r)>>1;
if(siz[k<<1] >= s) return find(k<<1, l, mid, s);
return find(k<<1|1, mid+1, r, s-siz[k<<1]);
}
} t;
void add(int w) {
++ ct[b[w]]; tot++;
t.add(1, 1, n, b[w], 1);
t.modify(1, 1, n, b[w]+1, n, -a[w]);
}
void del(int w) {
-- ct[b[w]]; tot--;
t.add(1, 1, n, b[w], -1);
t.modify(1, 1, n, b[w]+1, n, a[w]);
}
map <int, int> rk;
void init() {
sort(a1+1, a1+n+1); int cnt = 0;
for(int i = 1; i <= n; i++) {
if(a1[i] != a1[i-1]) ++ cnt;
rk[a1[i]] = cnt; id[cnt] = a1[i];
}
for(int i = 1; i <= n; i++) b[i] = rk[a[i]];
for(int i = 1; i <= n; i++) {
t.modify(1, 1, n, i, i, id[i]-inf);
}
} // 离散化
int rd() {
int number = 0;
char ch = getchar();
while(!isdigit(ch)) ch = getchar();
while(isdigit(ch))
number = number * 10 + ch - '0',
ch = getchar();
return number;
}
void print(ll s) {
if (s > 9) print (s / 10);
putchar('0' + s % 10);
}
int main() {
// freopen("data.in","r",stdin);
// freopen("me.out","w",stdout);
n = rd(); m = rd();
kc = sqrt(n);
for (int i = 1; i <= n; i++)
a[i] = rd(), a1[i] = a[i];
init();
for (int i = 1; i <= m; i++) {
q[i].l = rd(); q[i].r = rd(); q[i].k = rd();
q[i].id = i;
}
sort(q+1, q+m+1, cmp1);
int L = 1, R = 0;
for (int i = 1; i <= m; i++) {
while (R < q[i].r) add(++R);
while (R > q[i].r) del(R--);
while (L > q[i].l) add(--L);
while (L < q[i].l) del(L++);
int l = 1, r = tot, ans = tot+1;
while (l <= r) {
int mid = (l + r) >> 1;
int bi = t.find(1, 1, n, mid);
if(t.query(1, 1, n, 1, bi-(ct[bi]==1)) + q[i].k <= id[bi] &&
t.query(1, 1, n, bi+1, n) + q[i].k <= 0) ans = mid, r = mid-1;
else l = mid+1;
}
q[i].ans = tot + 1 - ans;
}
sort(q+1, q+m+1, cmp2);
for (int i = 1; i <= m; i++)
print(q[i].ans), putchar('\n');
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 18464kb
input:
28119 2 4 2 2 2 1 4 2 2 2 2 1 2 2 1 2 2 3 2 4 2 4 4 2 2 2 2 2 2 2 4 4 3 2 2 1 4 2 2 4 4 4 4 2 2 2 4 2 2 2 2 2 2 2 2 2 1 2 2 1 2 2 1 2 2 1 2 2 2 2 2 1 2 4 2 2 2 1 2 2 1 2 2 1 4 2 2 2 2 2 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 4 2 7 2 2 1 2 4 2 2 2 1 4 2 2 2 4 2 2 2 1 2 4 4 2 2 1 2 2 1 2 2 1 4 2 2 2 2 2 2 2 1 ...
output:
1 0
result:
wrong answer Incorrect output (test case 1)
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 0ms
memory: 15904kb
input:
311 2 2 1 12 12 14 6 6 6 40 40 297 28 28 82 30 30 74 4 4 10 38 38 210 6 6 4 42 42 365 8 8 11 16 16 30 6 6 7 22 22 38 10 10 5 2 2 2 12 12 19 16 16 52 28 28 124 26 26 92 2 2 2 28 28 25 20 20 19 18 18 43 4 4 3 30 30 78 26 26 130 18 18 58 26 26 59 6 6 4 10 10 6 14 14 34 18 18 184 12 12 108 18 18 35 30 3...
output:
1 1
result:
wrong answer Incorrect output (test case 1)
Subtask #5:
score: 0
Wrong Answer
Test #19:
score: 0
Wrong Answer
time: 6ms
memory: 16012kb
input:
310 44 2 22 36 8 195 2 2 4 2 50 61 12 42 275 4 4 5 26 30 416 24 20 252 20 32 498 30 30 130 32 48 1153 46 16 574 4 40 89 6 28 64 10 16 9 18 42 152 4 14 1 6 50 280 10 10 87 44 24 395 2 2 4 40 46 273 34 34 607 22 22 300 40 40 1166 10 48 211 42 22 334 6 10 20 38 38 189 6 10 36 14 14 33 44 48 1518 32 18 ...
output:
0 0 0 0 0 0 1 0 0 7 0 0 0 0 1 13 0 0 0 0 0 0 0 25 0 0 0 1 0 0 0 0 0 0 8 0 0 30 7 0 0 0 0 0
result:
wrong answer Incorrect output (test case 1)
Subtask #6:
score: 0
Skipped
Dependency #1:
0%