#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> ii;
const ll inf=1e18;
const ll maxn=3e5+5;
const ll mod=1e9+7;
vector<ll> adj[maxn];
ll arr[maxn];
ll n,e,op,ele,a,b,c;
vector<tuple<ll,ll,ll>> v;
ll fen[maxn];
void upd(ll x, ll y, ll val){
while (x<maxn){
fen[x]+=val;
x+=(x&-x);
}
y++;
while (y<maxn){
fen[y]-=val;
y+=(y&-y);
}
}
ll query(ll p){
ll ans=0;
while (p){
ans+=fen[p];
p-=(p&-p);
}
return ans;
}
ll ans[maxn];
queue<tuple<ll,ll,vector<ll>>> q;
ll curr=0;
void solve(ll l, ll r, vector<ll> &pple){
if (l==0) memset(fen,0,sizeof(fen)),curr=0; //do a reset
if (l==r){
for (auto u:pple) ans[u]=l; //done
return;
}
ll m=(l+r)>>1;
for (int i=curr;i<=m;i++){
tie(a,b,c) = v[i];
if (a<=b) upd(a,b,c);
else upd(1,b,c),upd(a,e,c); //add all up to m operations
}
vector<ll> can,cannot;
for (auto u:pple){
ll tot=0;
for (auto x:adj[u]){
tot+=query(x);
}
if (tot>=arr[u]) can.emplace_back(u);
else cannot.emplace_back(u);
}
curr=m+1;
q.emplace(l,m,can);
q.emplace(m+1,r,cannot);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>e;
vector<ll> pple;
for (int i=1;i<=e;i++){
cin>>ele;
adj[ele].emplace_back(i);
}
for (int i=1;i<=n;i++){
cin>>arr[i];
pple.emplace_back(i);
}
cin>>op;
for (int i=1;i<=op;i++){
cin>>a>>b>>c;
v.emplace_back(a,b,c);
}
v.emplace_back(1,e,mod); //i hate overflow
q.emplace(0,op,pple);
while (q.size()){
tie(a,b,pple) = q.front();
q.pop();
solve(a,b,pple);
}
for (int i=1;i<=n;i++){
if (ans[i]==op) cout<<"NIE"<<endl;
else cout<<ans[i]+1<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9812 KB |
Output is correct |
2 |
Correct |
7 ms |
9812 KB |
Output is correct |
3 |
Correct |
7 ms |
9812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9812 KB |
Output is correct |
2 |
Correct |
6 ms |
9812 KB |
Output is correct |
3 |
Correct |
8 ms |
9812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
13064 KB |
Output is correct |
2 |
Correct |
185 ms |
14348 KB |
Output is correct |
3 |
Correct |
113 ms |
13888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
13524 KB |
Output is correct |
2 |
Correct |
138 ms |
13552 KB |
Output is correct |
3 |
Correct |
186 ms |
14108 KB |
Output is correct |
4 |
Correct |
47 ms |
11492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
13292 KB |
Output is correct |
2 |
Correct |
184 ms |
14292 KB |
Output is correct |
3 |
Correct |
132 ms |
12332 KB |
Output is correct |
4 |
Correct |
130 ms |
14232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
12816 KB |
Output is correct |
2 |
Correct |
169 ms |
13440 KB |
Output is correct |
3 |
Correct |
85 ms |
13032 KB |
Output is correct |
4 |
Correct |
168 ms |
14704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1031 ms |
36864 KB |
Output is correct |
2 |
Incorrect |
683 ms |
29948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1052 ms |
36180 KB |
Output is correct |
2 |
Incorrect |
753 ms |
30004 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |