#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
/*
const int MOD = ;
inline void mod(int &x) {
if(x >= MOD)
x -= MOD;
}
inline void add(int &x, int y) {
x += y;
mod(x);
}
inline void sub(int &x, int y) {
x += MOD - y;
mod(x);
}
inline void mul(int &x, int y) {
x = (1LL * x * y) % MOD;
}
*/
using namespace std;
const int MAXN = (int) 3e5;
ll aint[4 * MAXN + 1];
void update(int nod, int left, int right, int l, int r, int val) {
if(l <= left && right <= r) {
aint[nod] += val;
}
else {
int mid = (left + right) / 2;
if(l <= mid) update(2 * nod, left, mid, l, r, val);
if(mid < r) update(2 * nod + 1, mid + 1, right, l, r, val);
}
}
ll query(int nod, int left, int right, int pos) {
if(left == right) {
return aint[nod];
}
else {
int mid = (left + right) / 2;
ll ans = aint[nod];
if(pos <= mid) ans += query(2 * nod, left, mid, pos);
else ans += query(2 * nod + 1, mid + 1, right, pos);
return ans;
}
}
vector <int> pos[MAXN + 1];
int o[MAXN + 1], q[MAXN + 1];
int l[MAXN + 1], r[MAXN + 1], a[MAXN + 1];
int n, m, k;
pair <int, int> res[MAXN + 1];
inline void check(int step) {
for(int i = 1; i <= 4 * m; i++) {
aint[i] = 0;
}
sort(res + 1, res + n + 1);
int p = 1;
for(int i = 1; i <= n; i++) {
while(p <= res[i].first + step && p <= k) {
if(l[p] <= r[p]) {
update(1, 1, m, l[p], r[p], a[p]);
}
else {
update(1, 1, m, 1, r[p], a[p]);
update(1, 1, m, l[p], m, a[p]);
}
p++;
}
ll cur = 0;
for(auto it : pos[res[i].second]) {
cur += query(1, 1, m, it);
}
if(cur < q[res[i].second]) {
res[i].first += step;
}
}
}
int sol[MAXN + 1];
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for(i = 1; i <= m; i++) {
cin >> o[i];
pos[o[i]].push_back(i);
}
for(i = 1; i <= n; i++) {
cin >> q[i];
}
cin >> k;
for(i = 1; i <= k; i++) {
cin >> l[i] >> r[i] >> a[i];
}
for(i = 1; i <= n; i++) {
res[i] = {-1, i};
}
for(int step = 1 << 18; step; step >>= 1) {
check(step);
}
for(i = 1; i <= n; i++) {
sol[res[i].second] = res[i].first + 1;
}
for(i = 1; i <= n; i++) {
if(sol[i] == (1 << 19) - 1) {
cout << "NIE\n";
}
else {
cout << sol[i] << "\n";
}
}
//cin.close();
//cout.close();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
7552 KB |
Output is correct |
2 |
Correct |
13 ms |
7552 KB |
Output is correct |
3 |
Correct |
13 ms |
7552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
7552 KB |
Output is correct |
2 |
Correct |
13 ms |
7552 KB |
Output is correct |
3 |
Correct |
13 ms |
7552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
344 ms |
11080 KB |
Output is correct |
2 |
Correct |
421 ms |
12152 KB |
Output is correct |
3 |
Correct |
449 ms |
11612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
390 ms |
11588 KB |
Output is correct |
2 |
Correct |
373 ms |
11512 KB |
Output is correct |
3 |
Correct |
433 ms |
12248 KB |
Output is correct |
4 |
Correct |
102 ms |
10492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
11080 KB |
Output is correct |
2 |
Correct |
273 ms |
12264 KB |
Output is correct |
3 |
Correct |
86 ms |
8572 KB |
Output is correct |
4 |
Correct |
411 ms |
11920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
200 ms |
11136 KB |
Output is correct |
2 |
Correct |
350 ms |
11616 KB |
Output is correct |
3 |
Correct |
332 ms |
11388 KB |
Output is correct |
4 |
Correct |
417 ms |
12484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4075 ms |
35288 KB |
Output is correct |
2 |
Incorrect |
1309 ms |
30712 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4085 ms |
34660 KB |
Output is correct |
2 |
Incorrect |
1215 ms |
29360 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |