#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int nmax = 300005;
int n, m, k, a[nmax], p[nmax], x[nmax], y[nmax], z[nmax], ans[nmax], curr, tree[nmax];
vector<int>members[nmax];
void add(int pos, int val){
for(int i=pos;i<nmax;i+=(i&-i)){
tree[i] += val;
}
}
int query(int pos){
if(!pos) return 0LL;
int ans = 0;
for(int i=pos;i>=1;i-=(i&-i)){
ans += tree[i];
}
return ans;
}
void rec(int l, int r, vector<int>&pending){
if(r < l) return;
int mid = l + (r - l) / 2;
while(curr < mid){
curr++;
if(x[curr] <= y[curr]){
add(x[curr], z[curr]);
add(y[curr]+1, -z[curr]);
}
else{
add(x[curr], z[curr]);
add(m+1, -z[curr]);
add(1, z[curr]);
add(y[curr]+1, -z[curr]);
}
}
while(curr > mid){
int fuck = z[curr] * (-1LL);
if(x[curr] <= y[curr]){
add(x[curr], fuck);
add(y[curr]+1, -fuck);
}
else{
add(x[curr], fuck);
add(m+1, -fuck);
add(1, fuck);
add(y[curr]+1, -fuck);
}
--curr;
}
vector<int>good;
vector<int>bad;
for(auto it : pending){
int curr = 0;
for(auto it1 : members[it]){
curr += (query(it1));
}
if(curr >= p[it]){
good.push_back(it);
ans[it] = mid;
}
else{
bad.push_back(it);
}
}
pending.clear();
if(l != r){
rec(l, mid - 1, good);
rec(mid + 1, r, bad);
}
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
//freopen("input.in", "r", stdin);
cin >> n >> m;
for(int i=1;i<=m;i++){
cin >> a[i];
members[a[i]].push_back(i);
}
for(int i=1;i<=n;i++){ cin >> p[i];}
cin >> k;
for(int i=1;i<=k;i++){
cin >> x[i] >> y[i] >> z[i];
}
vector<int>tz;
for(int i=1;i<=n;i++) tz.push_back(i);
rec(1, k, tz);
for(int i=1;i<=n;i++){
if(!ans[i]){
cout << "NIE" << '\n';
}
else{
cout << ans[i] << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7508 KB |
Output is correct |
2 |
Correct |
5 ms |
7508 KB |
Output is correct |
3 |
Correct |
5 ms |
7508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7508 KB |
Output is correct |
2 |
Correct |
5 ms |
7508 KB |
Output is correct |
3 |
Correct |
5 ms |
7508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
10820 KB |
Output is correct |
2 |
Correct |
111 ms |
14076 KB |
Output is correct |
3 |
Correct |
77 ms |
10804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
10516 KB |
Output is correct |
2 |
Correct |
83 ms |
10532 KB |
Output is correct |
3 |
Correct |
107 ms |
12680 KB |
Output is correct |
4 |
Correct |
27 ms |
10444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
10472 KB |
Output is correct |
2 |
Correct |
119 ms |
13092 KB |
Output is correct |
3 |
Correct |
67 ms |
8660 KB |
Output is correct |
4 |
Correct |
68 ms |
11008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
9936 KB |
Output is correct |
2 |
Correct |
108 ms |
10576 KB |
Output is correct |
3 |
Correct |
56 ms |
10080 KB |
Output is correct |
4 |
Correct |
107 ms |
12168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
684 ms |
36656 KB |
Output is correct |
2 |
Incorrect |
453 ms |
21524 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
641 ms |
33136 KB |
Output is correct |
2 |
Incorrect |
479 ms |
21616 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |