#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
#define int ll
using namespace std;
using ll = long long;
const int N = 3e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7 , P = 6547;
int p[N] , n , m , k ;
int L[N] , R[N] , res[N];
int l[N] , r[N] , c[N];
ll t[N];
vector<int> g[N] , v;
deque<pair<int,int>> q;
void upd(int i, int x) {
for(; i <= m; i |= (i + 1)) t[i] += x;
}
void updlr(int l, int r, int x){
upd(l, x); upd(r + 1, -x);
}
ll get(int i){
ll res = 0;
for(; i > 0; i = (i & (i + 1)) - 1) res += t[i];
ll con = 1000000000;
return min(res,con);
}
void cl(){
for(int i = 0; i <= m; i++) t[i] = 0;
}
void solve(){
cin >> n >> m;
for(int i = 1; i <= m; i++) {
int a;
cin >> a;
g[a].push_back(i);
}
for(int i = 1; i <= n; i++) cin >> p[i];
cin >> k;
for(int i = 1; i <= n; i++) {
L[i] = 1;
R[i] = k;
q.push_back(make_pair((k+1)/2,i));
}
for(int i = 1; i <= k; i++) cin >> l[i] >> r[i] >> c[i];
for(int _ = 1; _ <= 20; _++){
cl();
sort(all(q));
for(int i = 1; i <= k; i++){
if(l[i] > r[i]){
updlr(l[i],m,c[i]);
updlr(1,r[i],c[i]);
} else updlr(l[i],r[i],c[i]);
while(!q.empty() && q.front().F == i){
int x = q.front().S;
q.pop_front();
ll sum = p[x];
for(int j = 0 ; j < g[x].size(); j++) sum -= get(g[x][j]);
if(sum <= 0){
res[x] = i;
R[x] = i-1;
} else {
L[x] = i+1;
}
if(L[x] <= R[x]) q.push_back({(L[x]+R[x])/2,x});
}
}
}
for(int i = 1; i <= n; i++) {
if(res[i] == 0){
cout << "NIE\n";
} else {
cout << res[i] << "\n";
}
}
}
/*
*/
signed main(){
ios;
solve();
return 0;
}
Compilation message
met.cpp: In function 'void solve()':
met.cpp:65:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int j = 0 ; j < g[x].size(); j++) sum -= get(g[x][j]);
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7508 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
5 ms |
7508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
9740 KB |
Output is correct |
2 |
Correct |
112 ms |
11080 KB |
Output is correct |
3 |
Correct |
78 ms |
10380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
10084 KB |
Output is correct |
2 |
Correct |
86 ms |
10192 KB |
Output is correct |
3 |
Correct |
119 ms |
11092 KB |
Output is correct |
4 |
Correct |
32 ms |
9400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
9904 KB |
Output is correct |
2 |
Correct |
81 ms |
10960 KB |
Output is correct |
3 |
Correct |
37 ms |
8636 KB |
Output is correct |
4 |
Correct |
80 ms |
10564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
9504 KB |
Output is correct |
2 |
Correct |
122 ms |
10056 KB |
Output is correct |
3 |
Correct |
53 ms |
9664 KB |
Output is correct |
4 |
Correct |
106 ms |
11248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1212 ms |
27516 KB |
Output is correct |
2 |
Correct |
811 ms |
19276 KB |
Output is correct |
3 |
Correct |
162 ms |
13312 KB |
Output is correct |
4 |
Correct |
1874 ms |
37604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1143 ms |
26552 KB |
Output is correct |
2 |
Correct |
781 ms |
19276 KB |
Output is correct |
3 |
Correct |
137 ms |
12116 KB |
Output is correct |
4 |
Correct |
2268 ms |
40080 KB |
Output is correct |