/**
* LES GREATEABLES BRO TEAM
**/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define sz(x) (int)x.size()
const bool FLAG = false;
void setIO(const string &f = "");
#define int ll
const int N = 3e5 + 13;
int t[4 * N];
inline void upd(int l, int r, int v, int x, int lx, int rx) {
if (r < lx || rx < l) return;
if (l <= lx && rx <= r) {
t[x] += v;
return;
}
int mid = (lx + rx) / 2;
upd(l, r, v, 2 * x + 1, lx, mid);
upd(l, r, v, 2 * x + 2, mid + 1, rx);
}
inline int get(int i, int x, int lx, int rx) {
if (lx == rx)
return t[x];
int mid = (lx + rx) / 2;
if (i <= mid)
return get(i, 2 * x + 1, lx, mid) + t[x];
else
return get(i, 2 * x + 2, mid + 1, rx) + t[x];
}
inline void clear(int x, int lx, int rx) {
if (lx == rx)
t[x] = 0;
int mid = (lx + rx) / 2;
clear(2 * x + 1, lx, mid);
clear(2 * x + 2, mid + 1, rx);
}
void solve() {
int n, m;
cin >> n >> m;
vector<int> o(m + 1);
for (int i = 1; i <= m; i++)
cin >> o[i];
vector<int> p(n + 1);
for (int i = 1; i <= n; i++)
cin >> p[i];
int q;
cin >> q;
vector<int> l(q + 1), r(q + 1), a(q + 1);
for (int i = 1; i <= q; i++) {
cin >> l[i] >> r[i] >> a[i];
}
for (int i = 1; i <= n; i++) {
int lo = 1, hi = q, res = -1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
vector<int> sc(m + 2);
for (int rep = 1; rep <= mid; rep++) {
if (l[rep] <= r[rep])
sc[l[rep]] += a[rep], sc[r[rep] + 1] -= a[rep];
else {
sc[l[rep]] += a[rep];
sc[m + 1] -= a[rep];
sc[1] += a[rep];
sc[r[rep] + 1] -= a[rep];
}
}
int cur_p = 0;
for (int j = 1; j <= m; j++) {
sc[j] += sc[j - 1];
if (o[j] == i)
cur_p += sc[j];
}
if (cur_p >= p[i])
hi = mid - 1, res = mid;
else
lo = mid + 1;
}
if (res == -1)
cout << "NIE\n";
else
cout << res << '\n';
}
}
signed main() {
setIO();
int tt = 1;
if (FLAG) {
cin >> tt;
}
while (tt--) {
solve();
}
return 0;
}
void setIO(const string &f) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen((f + ".in").c_str(), "r")) {
freopen((f + ".in").c_str(), "r", stdin);
freopen((f + ".out").c_str(), "w", stdout);
}
}
Compilation message
met.cpp: In function 'void setIO(const string&)':
met.cpp:113:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
113 | freopen((f + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
114 | freopen((f + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
360 KB |
Output is correct |
2 |
Correct |
48 ms |
348 KB |
Output is correct |
3 |
Correct |
13 ms |
360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
332 KB |
Output is correct |
2 |
Correct |
13 ms |
360 KB |
Output is correct |
3 |
Correct |
55 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6027 ms |
2316 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6063 ms |
2352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6036 ms |
2364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1518 ms |
2284 KB |
Output is correct |
2 |
Execution timed out |
6059 ms |
2376 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6088 ms |
12844 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6058 ms |
12700 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |