Submission #391142

# Submission time Handle Problem Language Result Execution time Memory
391142 2021-04-18T05:19:12 Z Pichon5 Meteors (POI11_met) C++17
74 / 100
551 ms 41496 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[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(ll pos, ll val){
    while(pos<=m){
        T[pos]+=val;
        pos+=(pos&-pos);
    }
}
ll query(ll pos){
   ll res=0ll;
   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(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>=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(r+1,-val);
    }  
    parallel(b,mid-1,A);
}
int main()
{
    fast
    ll x;
    cin>>n>>m;
    G.assign(n+1,vll());
    for(int i=0;i<tam;i++)res[i]=INF;
    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=1;i<=n;i++)aux.pb(i);
    parallel(0,k-1,aux);
    for(int i=1;i<=n;i++){
        if(res[i]==INF){
            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:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int i=0;i<q.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2764 KB Output is correct
2 Correct 3 ms 2764 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2764 KB Output is correct
2 Correct 2 ms 2764 KB Output is correct
3 Correct 3 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 6372 KB Output is correct
2 Correct 78 ms 12856 KB Output is correct
3 Correct 93 ms 6196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 5716 KB Output is correct
2 Correct 85 ms 5700 KB Output is correct
3 Correct 75 ms 9932 KB Output is correct
4 Correct 29 ms 6508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 5596 KB Output is correct
2 Correct 81 ms 10540 KB Output is correct
3 Correct 23 ms 4292 KB Output is correct
4 Correct 86 ms 6720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 4800 KB Output is correct
2 Correct 89 ms 6032 KB Output is correct
3 Correct 50 ms 5008 KB Output is correct
4 Correct 101 ms 8384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 551 ms 41496 KB Output is correct
2 Incorrect 279 ms 18096 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 524 ms 34940 KB Output is correct
2 Incorrect 302 ms 18104 KB Output isn't correct
3 Halted 0 ms 0 KB -