Submission #254136

#TimeUsernameProblemLanguageResultExecution timeMemory
254136NucleistTenis (COI19_tenis)C++14
39 / 100
520 ms9336 KiB
//Self-control leads to consistency. #include <bits/stdc++.h> using namespace std; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define debug(x) cerr << " - " << #x << ": " << x << endl; #define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl; #define all(x) (x).begin(),(x).end() #define sz(x) (ll)x.size() #define ll long long #define INF 1000000000 #define MOD 1000000007 #define pb push_back #define ve vector<ll> #define dos pair<ll,ll> #define vedos vector<dos> #define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define EPS 0.000001 struct greateri { template<class T> bool operator()(T const &a, T const &b) const { return a > b; } }; void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } ll seg[400011]; ll ari[400011]; pair<int,dos> zi[400011]; void upd(ll p,ll l,ll r,ll k,ll val){ if(l==r && l==k){ seg[p]=max(seg[p],val); return; } ll med=(l+r)>>1; if(k<=med){ upd(p*2,l,med,k,val); } else upd(p*2+1,med+1,r,k,val); seg[p]=max(seg[p*2],seg[p*2+1]); } ll query(ll p,ll l,ll r,ll l1,ll r1){ if(l>r || l>r1 || l1>r)return 0; if(l>=l1 && r<=r1)return seg[p]; ll med=(l+r)>>1; return max(query(p*2,l,med,l1,r1),query(p*2+1,med+1,r,l1,r1)); } int main() { //flash; ll n,q; cin>>n>>q; for (ll i = 0; i < n; ++i) { ll yo; cin>>yo; yo--; ari[i]=yo; zi[yo].first=i; } for (ll i = 0; i < n; ++i) { ll yo; cin>>yo; yo--; zi[yo].second.first=i; } for (ll i = 0; i < n; ++i) { ll yo; cin>>yo; yo--; zi[yo].second.second=i; } for (int i = 0; i < n; ++i) { upd(1,0,n-1,zi[i].first,max(zi[i].second.first,zi[i].second.second)); } ll l=0,r=0; set<ll>ans; while(query(1,0,n-1,l,r)+1!=(r-l+1)){ ll cur=query(1,0,n-1,l,r); r++; } for (ll i = 0; i <= r; ++i) { ans.insert(ari[i]); } while(q--){ ll na; cin>>na; if(na==1){ ll x; cin>>x; x--; if(ans.find(x)!=ans.end()){ cout<<"DA"<<'\n'; } else cout<<"NE"<<'\n'; } else{ int x,y,z; cin>>x>>y>>z; y--,z--; if(x==1){ ari[zi[y].first]=z; ari[zi[z].first]=y; swap(zi[y].first,zi[z].first); } if(x==2)swap(zi[y].second.first,zi[z].second.first); if(x==3)swap(zi[y].second.second,zi[z].second.second); memset(seg,0,sizeof seg); for (int i = 0; i < n; ++i) { upd(1,0,n-1,zi[i].first,max(zi[i].second.first,zi[i].second.second)); } ll l1=0,r1=0; ans.clear(); while(query(1,0,n-1,l1,r1)+1!=(r1-l1+1)){ ll cur=query(1,0,n-1,l1,r1); r1++; } for (ll i = 0; i <= r1; ++i) { ans.insert(ari[i]); } } } return 0; }

Compilation message (stderr)

tenis.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
tenis.cpp:6:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
tenis.cpp: In function 'int main()':
tenis.cpp:86:8: warning: unused variable 'cur' [-Wunused-variable]
     ll cur=query(1,0,n-1,l,r);
        ^~~
tenis.cpp:124:12: warning: unused variable 'cur' [-Wunused-variable]
         ll cur=query(1,0,n-1,l1,r1);
            ^~~
tenis.cpp: In function 'void setIO(std::__cxx11::string)':
tenis.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".in").c_str(),"r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tenis.cpp:29:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".out").c_str(),"w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...