/**
* 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 = "");
string to_string(const string s) {
return '"' + s + '"';
}
string to_string(const char c) {
return char(39) + string(1, c) + char(39);
}
string to_string(const char* s) {
return to_string(string(s));
}
string to_string(bool f) {
return (f ? "true" : "false");
}
template<class A, class B>
string to_string(const pair<A, B> x) {
return "(" + to_string(x.first) + ", " + to_string(x.second) + ")";
}
template<class A, class B, class C>
string to_string(const tuple<A, B, C> x) {
return "(" + to_string(get<0>(x)) + ", " + to_string(get<1>(x)) + ", " + to_string(get<2>(x)) + ")";
}
template<class A, class B, class C, class D>
string to_string(const tuple<A, B, C, D> x) {
return "(" + to_string(get<0>(x)) + ", " + to_string(get<1>(x)) + ", " + to_string(get<2>(x)) + ", " + to_string(get<3>(x)) + ")";
}
template<class T>
string to_string(const T v) {
string res = "{"; bool f = true;
for (auto x: v)
res += (f ? to_string(x) : ", " + to_string(x)), f = false;
return res + "}";
}
void debug_args() { cerr << "]\n"; }
template<class H, class... T>
void debug_args(H x, T... y) {
cerr << to_string(x);
if (sizeof... (y))
cerr << ", ";
debug_args(y...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: [", debug_args(__VA_ARGS__);
#else
#define debug(...) 47
#endif
#define int ll
const int N = 3e6 + 13;
int n, m;
ll bit[N];
void upd(int x, ll v) {
for (; x <= m; x |= (x + 1))
bit[x] += v;
}
ll get(int x) {
ll res = 0;
for (; x > 0; x = (x & (x + 1)) - 1)
res += bit[x];
return res;
}
void clear() {
for (int x = 1; x <= m; x++)
bit[x] = 0;
}
void solve() {
cin >> n >> m;
vector<int> o(m + 1);
vector<vector<int>> occ(n + 1);
for (int i = 1; i <= m; i++) {
cin >> o[i];
occ[o[i]].push_back(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];
}
vector<int> left(n + 1, 1), right(n + 1, q), res(n + 1, -1);
while (true) {
clear();
vector<vector<int>> check(q + 1);
bool over = true;
for (int i = 1; i <= n; i++) {
if (left[i] <= right[i]) {
int mid = (left[i] + right[i]) / 2;
check[mid].push_back(i);
over = false;
}
}
if (over)
break;
for (int i = 1; i <= q; i++) {
if (l[i] <= r[i]) {
upd(l[i], a[i]);
upd(r[i] + 1, -a[i]);
} else {
upd(l[i], a[i]);
upd(m + 1, -a[i]);
upd(1, a[i]);
upd(r[i] + 1, -a[i]);
}
for (int x: check[i]) {
ll cur = 0;
for (int pos: occ[x]) {
cur += get(pos);
}
if (cur >= p[x]) {
right[x] = i - 1;
res[x] = i;
} else
left[x] = i + 1;
}
}
}
for (int i = 1; i <= n; i++) {
if (res[i] == -1)
cout << "NIE\n";
else
cout << res[i] << '\n';
}
}
signed main() {
setIO();
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:157:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
157 | freopen((f + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:158:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
158 | freopen((f + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
4440 KB |
Output is correct |
2 |
Correct |
91 ms |
6244 KB |
Output is correct |
3 |
Correct |
81 ms |
5284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
4828 KB |
Output is correct |
2 |
Correct |
77 ms |
4844 KB |
Output is correct |
3 |
Correct |
96 ms |
6152 KB |
Output is correct |
4 |
Correct |
27 ms |
3188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
4516 KB |
Output is correct |
2 |
Correct |
78 ms |
6216 KB |
Output is correct |
3 |
Correct |
49 ms |
2740 KB |
Output is correct |
4 |
Correct |
90 ms |
5596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
4120 KB |
Output is correct |
2 |
Correct |
89 ms |
4872 KB |
Output is correct |
3 |
Correct |
62 ms |
4304 KB |
Output is correct |
4 |
Correct |
106 ms |
6328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1183 ms |
32288 KB |
Output is correct |
2 |
Incorrect |
828 ms |
21548 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1173 ms |
31132 KB |
Output is correct |
2 |
Incorrect |
785 ms |
21548 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |