#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void io(string in = "", string out = "", string err = "") {
if(fopen(in.c_str(), "r")) {
freopen(in.c_str(), "r", stdin);
freopen(out.c_str(), "w", stdout);
#ifdef conv_local
freopen(err.c_str(), "w", stderr);
#endif
}
}
void conv();
int main() {
#ifdef conv_local
//io("in.txt", "out.txt", "err.txt");
auto st = chrono::steady_clock::now();
#else
#define TASKNAME ""
io(TASKNAME".inp", TASKNAME".out");
#endif
ios::sync_with_stdio(false); cin.tie(NULL);
int Q = 1;
//cin >> Q;
while(Q--) {
conv();
}
#ifdef conv_local
auto ed = chrono::steady_clock::now();
cout << "\nExcution Time: " << chrono::duration_cast<chrono::milliseconds> (ed - st).count() << "[ms]" << endl;
#endif
return 0;
}
typedef long long LL;
const int N = 300003;
const int M = N << 1;
int n, m, q, l[N], r[N], ql[N], qr[N], a[N], res[N];
LL f[M], p[N];
list<int> o[N];
void add(int x, LL d) {
for(; x < M; x += x&-x) f[x] += d;
}
LL query(int x) {
LL ret = 0;
for(; x > 0; x &= x - 1) ret += f[x];
return ret;
}
void conv() {
cin >> n >> m;
for(int i = 1; i <= m; ++i) {
int j;
cin >> j;
o[j].push_back(i);
}
for(int i = 1; i <= n; ++i) {
cin >> p[i];
}
cin >> q;
for(int i = 1; i <= q; ++i) {
cin >> ql[i] >> qr[i] >> a[i];
if(ql[i] > qr[i]) qr[i] += m;
}
for(int i = 1; i <= n; ++i) {
l[i] = 1;
r[i] = q + 1;
}
int ptr = 0;
while(1) {
vector<pair<int, int>> work;
for(int i = 1; i <= n; ++i) {
if(l[i] != r[i]) {
int qm = (l[i] + r[i]) >> 1;
work.emplace_back(qm, i);
}
}
if(work.empty()) break;
sort(work.begin(), work.end());
for(auto [qm, i] : work) {
while(ptr < qm) ++ptr, add(ql[ptr], a[ptr]), add(qr[ptr] + 1, -a[ptr]);
while(ptr > qm) add(ql[ptr], -a[ptr]), add(qr[ptr] + 1, a[ptr]), --ptr;
LL tot = 0;
for(int j : o[i]) tot += query(j) + query(j + m), assert(0 <= tot && tot <= (LL)1e18);
if(tot < p[i]) l[i] = qm + 1;
else r[i] = qm;
}
}
for(int i = 1; i <= n; ++i) {
if(l[i] > q) cout << "NIE" << '\n';
else cout << l[i] << '\n';
}
}
Compilation message
met.cpp: In function 'void conv()':
met.cpp:106:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
106 | for(auto [qm, i] : work) {
| ^
met.cpp: In function 'void io(std::string, std::string, std::string)':
met.cpp:31:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | freopen(in.c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen(out.c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
7500 KB |
Output is correct |
2 |
Correct |
6 ms |
7500 KB |
Output is correct |
3 |
Correct |
6 ms |
7500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
7520 KB |
Output is correct |
2 |
Correct |
6 ms |
7500 KB |
Output is correct |
3 |
Correct |
8 ms |
7500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
10500 KB |
Output is correct |
2 |
Correct |
186 ms |
11260 KB |
Output is correct |
3 |
Correct |
188 ms |
10760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
135 ms |
10688 KB |
Output is correct |
2 |
Correct |
142 ms |
10656 KB |
Output is correct |
3 |
Correct |
198 ms |
11220 KB |
Output is correct |
4 |
Correct |
50 ms |
9952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
195 ms |
10160 KB |
Output is correct |
2 |
Correct |
186 ms |
10820 KB |
Output is correct |
3 |
Correct |
67 ms |
8144 KB |
Output is correct |
4 |
Correct |
164 ms |
11160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
10308 KB |
Output is correct |
2 |
Correct |
165 ms |
10820 KB |
Output is correct |
3 |
Correct |
93 ms |
10384 KB |
Output is correct |
4 |
Correct |
188 ms |
11352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1141 ms |
28516 KB |
Output is correct |
2 |
Runtime error |
133 ms |
43392 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1160 ms |
28196 KB |
Output is correct |
2 |
Runtime error |
143 ms |
43336 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |