Submission #391149

# Submission time Handle Problem Language Result Execution time Memory
391149 2021-04-18T05:27:27 Z Pichon5 Meteors (POI11_met) C++17
100 / 100
1257 ms 51984 KB
#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=300030;
const ll INF=1e16;
unsigned long long T[2*tam];
ll n,m,k;
vector<vll>G;
ll E[tam];
ll res[tam];
vector<pair<pair<ll,ll>,ll > >Q;//estas son las queries
void update(int pos, int val){
    while(pos<=m){
        T[pos]+=val;
        pos+=(pos&-pos);
    }
}
ll query(ll pos){
   unsigned long long res=0;
   while(pos>0){
       res+=T[pos];
       pos-=(pos&-pos);
   } 
   return res;
}
 
void parallel(ll b,ll e, vll q){
    if(q.size()==0 or e<b)return ;
    ll mid=(b+e)/2;
    //memset(T,0,sizeof T);
    for(int i=b;i<=mid;i++){
        ll l=Q[i].F.F,r=Q[i].F.S,val=Q[i].S;
        update(l,val);
        if(r<l){
            update(1,val);
            update(m+1,-val);
        }
        update(r+1,-val);
    }      
    vll A,B;
    for(int i=0;i<q.size();i++){
        ll sum=0ll;
        for(auto it : G[q[i]]){
            sum+=query(it);
            if (sum >= 1e10) break;
        }
        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=b;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(m+1,-val);
        }
        update(r+1,-val);
    }  
    parallel(b,mid-1,A);
}
int main()
{
    fast
    ll x;
    cin>>n>>m;
    G.assign(n+1,vll());
    for(int i=1;i<=m;i++){
        cin>>x;
        G[x].pb(i);
    }  
    for(int i=1;i<=n;i++){
        cin>>E[i];
    }
    ll l,r,val;
    cin>>k;
    for(int i=0;i<k;i++){
        cin>>l>>r>>val;
        Q.pb({{l,r},val});
    }
    vll aux;
    for(int i=0;i<=n;i++)res[i]=k+1;
    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]==k+1){
            cout<<"NIE"<<"\n";
        }else{
            cout<<res[i]<<"\n";
        }
    }        
    return 0;
}

Compilation message

met.cpp: In function 'void parallel(long long int, long long int, std::vector<long long int>)':
met.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i=0;i<q.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 4040 KB Output is correct
2 Correct 78 ms 10728 KB Output is correct
3 Correct 88 ms 4036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 3456 KB Output is correct
2 Correct 87 ms 3436 KB Output is correct
3 Correct 69 ms 7796 KB Output is correct
4 Correct 29 ms 4368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 3364 KB Output is correct
2 Correct 85 ms 8392 KB Output is correct
3 Correct 23 ms 1988 KB Output is correct
4 Correct 101 ms 4540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 2552 KB Output is correct
2 Correct 82 ms 3552 KB Output is correct
3 Correct 57 ms 2900 KB Output is correct
4 Correct 122 ms 6404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 546 ms 39840 KB Output is correct
2 Correct 177 ms 15724 KB Output is correct
3 Correct 125 ms 8664 KB Output is correct
4 Correct 1108 ms 42156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 502 ms 33248 KB Output is correct
2 Correct 238 ms 15728 KB Output is correct
3 Correct 82 ms 9032 KB Output is correct
4 Correct 1257 ms 51984 KB Output is correct