This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
#define mp make_pair
//salida rapida "\n"
//DECIMALES fixed<<sp(n)<<x<<endl;
//gcd(a,b)= ax + by
//lCB x&-x
//set.erase(it) - ersases the element present at the required index//auto it = s.find(element)
//set.find(element) - iterator pointing to the given element if it is present else return pointer pointing to set.end()
//set.lower_bound(element) - iterator pointing to element greater than or equal to the given element
//set.upper_bound(element) - iterator pointing to element greater than the given element
// | ^
//__builtin_popcount(x)
using namespace std;
const int tam=400000;
ll T[tam];
int n,m,k;
vector<vi>G;
int E[tam];
ll res[tam];
vector<pair<pair<int,int>,int > >Q;//estas son las queries
void update(int pos, int val){
while(pos<=m){
T[pos]+=val;
pos+=(pos&-pos);
}
}
ll query(int pos){
ll res=0;
while(pos>0){
res+=T[pos];
pos-=(pos&-pos);
}
return res;
}
void parallel(int b, int e, vi q){
if(q.size()==0 or e<b)return ;
ll mid=(b+e)/2;
for(int i=0;i<=mid;i++){
int l=Q[i].F.F,r=Q[i].F.S,val=Q[i].S;
update(l,val);
if(r<l){
update(1,val);
}
update(r+1,-val);
}
vi A,B;
for(int i=0;i<q.size();i++){
ll sum=0;
for(auto it : G[q[i]]){
sum+=query(it);
}
if(sum>=E[q[i]]){
A.pb(q[i]);
res[q[i]]=min(res[q[i]],mid+1);
}else{
B.pb(q[i]);
}
}
parallel(mid+1,e,B);
for(int i=0;i<=mid;i++){
int l=Q[i].F.F,r=Q[i].F.S,val=-Q[i].S;
update(l,val);
if(r<l){
update(1,val);
}
update(r+1,-val);
}
parallel(b,mid-1,A);
}
int main()
{
fast
int x;
cin>>n>>m;
G.assign(n+1,vi());
for(int i=0;i<tam;i++)res[i]=1e9;
for(int i=1;i<=m;i++){
cin>>x;
G[x].pb(i);
}
for(int i=1;i<=n;i++){
cin>>E[i];
}
int l,r,val;
cin>>k;
for(int i=0;i<k;i++){
cin>>l>>r>>val;
Q.pb({{l,r},val});
}
vi aux;
for(int i=1;i<=n;i++)aux.pb(i);
parallel(0,k-1,aux);
for(int i=1;i<=n;i++){
if(res[i]==1e9){
cout<<"NIE"<<"\n";
}else{
cout<<res[i]<<"\n";
}
}
return 0;
}
Compilation message (stderr)
met.cpp: In function 'void parallel(int, int, std::vector<int>)':
met.cpp:56:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i=0;i<q.size();i++){
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |