답안 #391129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391129 2021-04-18T04:50:22 Z Pichon5 Meteors (POI11_met) C++17
24 / 100
6000 ms 32212 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;
ll T[400000];
int n,m,k;
vector<vi>G;
vi E;
vll res;
vector<pair<pair<int,int>,int > >Q;//estas son las queries
void update(int pos, int val){
    while(pos<=m){
        T[pos]+=val;
        //cout<<pos<<" sumo "<<val<<endl;
        pos+=(pos&-pos);
        //cout<<"next  "<<pos<<endl;
    }
}
ll query(int pos){
   ll res=0;
   while(pos>0){
       //cout<<"sumo  "<<T[pos]<<endl;
       res+=T[pos];
       pos-=(pos&-pos);
   } 
   return res;
}

void parallel(int b, int e, vi q){
    //cout<<b<<"  "<<e<<endl;
    if(q.size()==0 or e<b)return ;
    ll mid=(b+e)/2;
    memset(T,0,sizeof T);
    for(int i=0;i<=mid;i++){
        int l=Q[i].F.F,r=Q[i].F.S,val=Q[i].S;
        //cout<<"updateo   "<<l<<"  "<<r<<"  "<<val<<endl;
        update(l,val);
        if(r<l){
            //cout<<"updateo  "<<r<<"  "<<val<<endl;
            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);
            //cout<<it<<" =  "<<query(it)<<endl;
        }
        //cout<<q[i]<<"  "<<mid<<"  "<<sum<<endl;
        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);
    parallel(b,mid-1,A);
}
int main()
{
    int x;
    cin>>n>>m;
    G.assign(n+1,vi());
    E.resize(n+1);res.assign(n+1,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"<<endl;
        }else{
            cout<<res[i]<<endl;
        }
    }        
    return 0;
}

Compilation message

met.cpp: In function 'void parallel(int, int, std::vector<int>)':
met.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i=0;i<q.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 3404 KB Output is correct
2 Correct 19 ms 3532 KB Output is correct
3 Correct 73 ms 3468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 3404 KB Output is correct
2 Correct 7 ms 3408 KB Output is correct
3 Correct 104 ms 3532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 6052 KB Output is correct
2 Correct 1251 ms 10176 KB Output is correct
3 Execution timed out 6052 ms 6332 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6050 ms 6136 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6023 ms 5552 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 959 ms 5472 KB Output is correct
2 Execution timed out 6054 ms 6292 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6027 ms 32212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6063 ms 28332 KB Time limit exceeded
2 Halted 0 ms 0 KB -