#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstring>
#include <cstdint>
struct Operation {
int l, r, amt;
Operation():
l(0), r(0), amt(0) {}
Operation(int l, int r, int amt):
l(l), r(r), amt(amt) {}
};
struct ParallelBSQuery {
int color;
int l, r, m;
ParallelBSQuery():
color(0), l(0), r(0), m(0) {}
ParallelBSQuery(int color, int l, int r):
color(color), l(l), r(r), m((l+r)>>1) {}
};
int x, q, ops;
int color[300005];
int target[300005];
int ans[300005];
uint64_t tree[1200005];
int lazy[1200005];
std::vector<Operation> operations;
std::vector<ParallelBSQuery> queries;
std::vector<int> owned_by[300005];
void push(int node, int l, int r) {
tree[node] += lazy[node];
if (l!=r) {
lazy[node<<1] += lazy[node];
lazy[node<<1|1] += lazy[node];
}
lazy[node] = 0;
}
void update(int node, int l, int r, int st, int fi, int val) {
push(node,l,r);
if (l>fi||r<st) {
return;
}
if (st<=l&&r<=fi) {
lazy[node] += val;
push(node,l,r);
return;
}
int m = (l+r)>>1;
update(node<<1,l,m,st,fi,val);
update(node<<1|1,m+1,r,st,fi,val);
tree[node] = tree[node<<1] + tree[node<<1|1];
}
uint64_t query(int node, int l, int r, int st, int fi) {
push(node,l,r);
if (l>fi||r<st) {
return 0;
}
if (st<=l&&r<=fi) {
return tree[node];
}
int m = (l+r)>>1;
return query(node<<1,l,m,st,fi) + query(node<<1|1,m+1,r,st,fi);
}
uint64_t get_sum(int color) {
uint64_t ret = 0;
for (const auto& i : owned_by[color]) {
ret += query(1,1,x,i,i);
}
return ret;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
std::cin >> q >> x;
for (int i = 1; i <= x; i++) {
std::cin >> color[i];
owned_by[color[i]].emplace_back(i);
}
for (int i = 1; i <= q; i++) {
std::cin >> target[i];
}
std::cin >> ops;
operations.reserve(ops);
for (int i = 0, l, r, amt; i < ops; i++) {
std::cin >> l >> r >> amt;
operations.emplace_back(l,r,amt);
}
for (int i = 0; i < q; i++) {
ans[i+1] = -1;
queries.emplace_back(i+1,0,ops-1);
}
for (int iterations = 0; iterations < 19; iterations++) {
memset(tree,0,sizeof(tree));
memset(lazy,0,sizeof(lazy));
std::sort(queries.begin(),queries.end(),[](const ParallelBSQuery& a, const ParallelBSQuery& b) {
return a.m < b.m;
});
int scanline = 0;
for (auto& [color, l, r, m] : queries) {
if (l>r) {
continue;
}
while (scanline<=m) {
auto [i, j, amt] = operations[scanline];
if (i>j) {
update(1,1,x,1,j,amt);
update(1,1,x,i,x,amt);
}
else {
update(1,1,x,i,j,amt);
}
++scanline;
}
uint64_t cand = get_sum(color);
if (cand>=target[color]) {
ans[color] = m;
r = m-1;
}
else {
l = m+1;
}
m = (l+r)>>1;
}
}
for (int i = 1; i <= q; i++) {
if (ans[i]==-1) std::cout << "NIE\n";
else std::cout << ans[i]+1 << "\n";
}
}
Compilation message
met.cpp: In function 'int main()':
met.cpp:137:12: warning: comparison of integer expressions of different signedness: 'uint64_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
137 | if (cand>=target[color]) {
| ~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
21596 KB |
Output is correct |
2 |
Correct |
19 ms |
21612 KB |
Output is correct |
3 |
Correct |
18 ms |
21596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
21592 KB |
Output is correct |
2 |
Correct |
18 ms |
21596 KB |
Output is correct |
3 |
Correct |
20 ms |
21640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
402 ms |
23820 KB |
Output is correct |
2 |
Correct |
454 ms |
25032 KB |
Output is correct |
3 |
Correct |
412 ms |
24276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
410 ms |
24280 KB |
Output is correct |
2 |
Correct |
412 ms |
24268 KB |
Output is correct |
3 |
Correct |
482 ms |
25040 KB |
Output is correct |
4 |
Correct |
132 ms |
23252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
241 ms |
23644 KB |
Output is correct |
2 |
Correct |
375 ms |
25052 KB |
Output is correct |
3 |
Correct |
81 ms |
22620 KB |
Output is correct |
4 |
Correct |
416 ms |
24780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
233 ms |
23632 KB |
Output is correct |
2 |
Correct |
446 ms |
24304 KB |
Output is correct |
3 |
Correct |
416 ms |
23632 KB |
Output is correct |
4 |
Correct |
461 ms |
25128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4158 ms |
40832 KB |
Output is correct |
2 |
Correct |
934 ms |
35440 KB |
Output is correct |
3 |
Correct |
522 ms |
26936 KB |
Output is correct |
4 |
Correct |
4741 ms |
46688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4198 ms |
40132 KB |
Output is correct |
2 |
Correct |
1396 ms |
33944 KB |
Output is correct |
3 |
Correct |
83 ms |
27388 KB |
Output is correct |
4 |
Correct |
4476 ms |
48596 KB |
Output is correct |