#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]) break; //prevent overflow
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9812 KB |
Output is correct |
2 |
Correct |
8 ms |
9804 KB |
Output is correct |
3 |
Correct |
8 ms |
9812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9812 KB |
Output is correct |
2 |
Correct |
7 ms |
9812 KB |
Output is correct |
3 |
Correct |
8 ms |
9812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
13104 KB |
Output is correct |
2 |
Correct |
190 ms |
14248 KB |
Output is correct |
3 |
Correct |
132 ms |
13860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
13536 KB |
Output is correct |
2 |
Correct |
141 ms |
13512 KB |
Output is correct |
3 |
Correct |
185 ms |
14344 KB |
Output is correct |
4 |
Correct |
48 ms |
11528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
13352 KB |
Output is correct |
2 |
Correct |
181 ms |
14340 KB |
Output is correct |
3 |
Correct |
119 ms |
12328 KB |
Output is correct |
4 |
Correct |
117 ms |
14048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
12836 KB |
Output is correct |
2 |
Correct |
165 ms |
13440 KB |
Output is correct |
3 |
Correct |
82 ms |
12984 KB |
Output is correct |
4 |
Correct |
163 ms |
14616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1006 ms |
36828 KB |
Output is correct |
2 |
Correct |
558 ms |
29872 KB |
Output is correct |
3 |
Correct |
609 ms |
27828 KB |
Output is correct |
4 |
Correct |
1594 ms |
52564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
991 ms |
36068 KB |
Output is correct |
2 |
Correct |
770 ms |
29968 KB |
Output is correct |
3 |
Correct |
520 ms |
23504 KB |
Output is correct |
4 |
Correct |
1905 ms |
55472 KB |
Output is correct |