Submission #204306

#TimeUsernameProblemLanguageResultExecution timeMemory
204306SegtreeTeams (IOI15_teams)C++14
34 / 100
4085 ms110788 KiB
#include"teams.h" #include<iostream> #include<algorithm> #include<vector> #include<queue> #include<unordered_set> using namespace std; typedef int ll; typedef pair<ll,ll> P; #define chmin(a,b) a=min(a,b) #define chmax(a,b) a=max(a,b) #define all(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<n;i++) #define mod 1000000007 #define mad(a,b) a=(a+b)%mod #pragma gcc optimize("O3") #pragma gcc optimize("unroll-loops") #pragma gcc target("avx2,see4") #define up(x,y) upper_bound(all(x),y) #define NS (1<<19) vector<P> v; ll dat[NS*2],laste[2*NS],lastd[2*NS],correctA; vector<ll> as[NS*2]; unordered_set<ll> used; void add(int K){ correctA=K; } ll eval(ll k){ if(k==0)return 0; if(k>100)used.insert(k); if(k<NS){ chmax(lastd[k*2],lastd[k]); if(k>100)used.insert(k*2); chmax(lastd[k*2+1],lastd[k]); if(k>100)used.insert(k*2+1); } if(lastd[k]==-1e9){ if(laste[k]!=correctA){ dat[k]+=up(as[k],correctA)-up(as[k],laste[k]); } } else{ dat[k]=up(as[k],correctA)-up(as[k],lastd[k]); } laste[k]=correctA; lastd[k]=-1e9; return dat[k]; } void erase(ll l,ll r){ l+=NS,r+=NS+1; for(ll d=20;~d;d--){ eval(l>>d); eval(r>>d); } for(ll a=l,b=r;a<b;a>>=1,b>>=1){ if(a&1){chmax(lastd[a],correctA);a++;} if(b&1){b--;chmax(lastd[b],correctA);} } for(ll a=l,b=r;a+b;a>>=1,b>>=1){ dat[a/2]=eval(a)+eval(a^1); dat[b/2]=eval(b)+eval(b^1); } } int sum(ll l,ll r){ l+=NS,r+=NS+1; ll res=0; for(ll d=20;~d;d--){ eval(l>>d); eval(r>>d); } for(ll a=l,b=r;a<b;a>>=1,b>>=1){ if(a&1){res+=eval(a);a++;} if(b&1){b--;res+=eval(b);} } return res; } void init(int N,int A[],int B[]){ rep(i,N)v.emplace_back(make_pair(B[i],A[i])); sort(v.begin(),v.end()); rep(i,NS){ if(i<N)as[i+NS].emplace_back(v[i].second); } for(int i=NS-1;i>0;i--){ for(auto t:as[i*2])as[i].emplace_back(t); for(auto t:as[i*2+1])as[i].emplace_back(t); sort(as[i].begin(),as[i].end()); } } int can(int M,int K[]){ used.clear(); for(int i=1;i<=100;i++)used.insert(i); correctA=0; sort(K,K+M); bool ans=1; rep(i,M){ add(K[i]); ll l,r,mid; l=-1,r=v.size(); while(l<r-1){ mid=(l+r)>>1; (v[mid].first<K[i]?l:r)=mid; } erase(0,l); if(eval(1)<K[i]){ ans=0; break; } ll k=1,rui=0; while(k<NS){ ll ev=eval(k*2); if(rui+ev>=K[i]){ k=k*2; } else{ rui+=ev; k=k*2+1; } } erase(0,k-NS); } for(auto i:used)dat[i]=0,laste[i]=lastd[i]=-1e9; return ans; } /* int main(){ int n,a[110],b[110]; cin>>n; rep(i,n)cin>>a[i]>>b[i]; init(n,a,b); while(1){ int m,k[110]; cin>>m; rep(i,m)cin>>k[i]; cout<<(can(m,k)?"YES":"NO")<<endl; } }*/

Compilation message (stderr)

teams.cpp:16:0: warning: ignoring #pragma gcc optimize [-Wunknown-pragmas]
 #pragma gcc optimize("O3")
 
teams.cpp:17:0: warning: ignoring #pragma gcc optimize [-Wunknown-pragmas]
 #pragma gcc optimize("unroll-loops")
 
teams.cpp:18:0: warning: ignoring #pragma gcc target [-Wunknown-pragmas]
 #pragma gcc target("avx2,see4")
 
teams.cpp: In function 'll eval(ll)':
teams.cpp:20:37: warning: conversion to 'll {aka int}' from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type {aka long int}' may alter its value [-Wconversion]
 #define up(x,y) upper_bound(all(x),y)
                                     ^
teams.cpp:38:31: note: in expansion of macro 'up'
    dat[k]+=up(as[k],correctA)-up(as[k],laste[k]);
                               ^~
teams.cpp:42:28: warning: conversion to 'll {aka int}' from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type {aka long int}' may alter its value [-Wconversion]
   dat[k]=up(as[k],correctA)-up(as[k],lastd[k]);
                            ^
teams.cpp: In function 'int can(int, int*)':
teams.cpp:99:16: warning: conversion to 'll {aka int}' from 'std::vector<std::pair<int, int> >::size_type {aka long unsigned int}' may alter its value [-Wconversion]
   l=-1,r=v.size();
          ~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...