//çalışan kazanır//
#include "bits/stdc++.h"
using namespace std;
//#define int long long
#define pb push_back
#define S second
#define F first
#define all(x) x.begin(),x.end()
#define YOSIK() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
int gcd (int a, int b) {if (b == 0){return a;}else {return gcd (b, a % b);}}
const int N = 3e5 + 15;
const int INF = 2e18 + 1;
const int MOD = 1e9 + 7;
const int MODD = 1070234587ll;
const double eps = 0.0001;
//const int p = 87;
int n, m, p[N], q, l[N], r[N], a[N], ans[N];
pair <int, int> brd[N];
vector <int> pos[N], MID[N];
long long t[N*4], mod[N*4];
void upd (int v, int tl, int tr, int ql, int qr, int val) {
if (tr < ql || qr < tl) return;
if (ql <= tl && tr <= qr) {
t[v] += val;
return;
}
int mid = (tl + tr) >> 1;
upd (v + v, tl, mid, ql, qr, val), upd (v + v + 1, mid + 1, tr, ql, qr, val);
return;
}
long long get (int v, int tl, int tr, int pos) {
if (tl == tr) return t[v];
int mid = (tl + tr) >> 1;
if (pos <= mid) return (t[v] + get (v + v, tl, mid, pos));
return (t[v] + get (v + v + 1, mid + 1, tr, pos));
}
void cl (int v, int tl, int tr) {
t[v] = 0;
if (tl == tr) return;
int mid = (tl + tr) >> 1;
cl (v + v, tl, mid), cl (v + v + 1, mid + 1, tr);
return;
}
void solution () {
cin >> n >> m;
int o;
for (int i = 1; i <= m; ++ i) {
cin >> o;
pos[o].pb (i);
}
for (int i = 1; i <= n; ++ i) cin >> p[i];
cin >> q;
for (int i = 1; i <= q; ++ i) cin >> l[i] >> r[i] >> a[i];
for (int i = 1; i <= n; ++ i) brd[i] = make_pair (1, q + 1);
long long sum = 0, ok = 1;
while (ok) {
memset (t, 0, sizeof(t));
ok = 0;
for (int i = 1; i <= n; ++ i) {
if (brd[i].F >= brd[i].S) continue;
MID[(brd[i].F + brd[i].S) >> 1].pb (i);
}
for (int mid = 1; mid <= q; ++ mid) {
if (l[mid] <= r[mid]) upd (1, 1, m, l[mid], r[mid], a[mid]);
else {
upd (1, 1, m, 1, r[mid], a[mid]);
upd (1, 1, m, l[mid], m, a[mid]);
}
for (auto i: MID[mid]) {
sum = 0, ok = 1;
for (auto j: pos[i]) {
sum += get (1, 1, m, j);
if (sum >= p[i]) break;
}
if (sum >= p[i]) brd[i].S = mid;
else brd[i].F = mid + 1;
}
MID[mid].clear();
}
}
for (int i = 1; i <= n; ++ i) {
if (brd[i].S == q + 1) cout << "NIE\n";
else cout << brd[i].S << '\n';
}
return;
}
signed main() {
YOSIK();
// srand (time(0));
// freopen ("E.in", "r", stdin);
// freopen ("E.out", "w", stdout);
int TT = 1;// cin >> TT;
for (int i = 1; i <= TT; ++ i) {
// cout << "Case " << i << ": ";
solution ();
}
return 0;
}
Compilation message
met.cpp:16:22: warning: overflow in conversion from 'double' to 'int' changes value from '2.0e+18' to '2147483647' [-Woverflow]
16 | const int INF = 2e18 + 1;
| ~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
29020 KB |
Output is correct |
2 |
Correct |
9 ms |
29228 KB |
Output is correct |
3 |
Correct |
9 ms |
29020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
29016 KB |
Output is correct |
2 |
Correct |
8 ms |
29020 KB |
Output is correct |
3 |
Correct |
9 ms |
29284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
234 ms |
30332 KB |
Output is correct |
2 |
Correct |
300 ms |
33624 KB |
Output is correct |
3 |
Correct |
286 ms |
31316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
282 ms |
30940 KB |
Output is correct |
2 |
Correct |
279 ms |
30804 KB |
Output is correct |
3 |
Correct |
291 ms |
33892 KB |
Output is correct |
4 |
Correct |
55 ms |
30804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
30308 KB |
Output is correct |
2 |
Correct |
192 ms |
34400 KB |
Output is correct |
3 |
Correct |
136 ms |
29528 KB |
Output is correct |
4 |
Correct |
279 ms |
31828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
255 ms |
29424 KB |
Output is correct |
2 |
Correct |
241 ms |
30944 KB |
Output is correct |
3 |
Correct |
257 ms |
29776 KB |
Output is correct |
4 |
Correct |
302 ms |
35036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2560 ms |
44712 KB |
Output is correct |
2 |
Correct |
1032 ms |
31264 KB |
Output is correct |
3 |
Correct |
694 ms |
29776 KB |
Output is correct |
4 |
Correct |
3161 ms |
65536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2479 ms |
43504 KB |
Output is correct |
2 |
Correct |
731 ms |
31268 KB |
Output is correct |
3 |
Correct |
570 ms |
30032 KB |
Output is correct |
4 |
Runtime error |
3042 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |