Submission #657729

#TimeUsernameProblemLanguageResultExecution timeMemory
657729inksamuraiAlternating Current (BOI18_alternating)C++17
19 / 100
32 ms6468 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define rng(i,c,n) for(int i=c;i<n;i++) #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define vec(...) vector<__VA_ARGS__> #define _3NRqilq ios::sync_with_stdio(0),cin.tie(0) typedef long long ll; using pii=pair<int,int>; using vi=vector<int>; void print(){cout<<'\n';} template<class h,class...t> void print(const h&v,const t&...u){cout<<v<<' ',print(u...);} #define nare {cout<<"impossible\n";exit(0);} signed main(){ _3NRqilq; int n,m; cin>>n>>m; vec(vec(pii)) adqry(n); rep(i,m){ int l,r; cin>>l>>r; assert(l<=r); l-=1,r-=1; adqry[l].pb({r,i}); } vi pns(m); vec(pii) _lst(2); // index,id _lst[0].fi=-1; _lst[0].se=0; _lst[1].fi=-1; _lst[1].se=1; rep(i,n){ for(auto p:adqry[i]){ int r=p.fi; int j=p.se; if(r>_lst[0].fi){ swap(_lst[0],_lst[1]); _lst[0].fi=r; pns[j]=_lst[0].se; }else if(r>_lst[1].fi){ _lst[1].fi=r; pns[j]=_lst[1].se; } if(_lst[0].fi<_lst[1].fi){ swap(_lst[0],_lst[1]); } } rep(j,2){ if(i>_lst[j].fi){ nare; } } } string _s; rep(i,m){ _s+=(char)(pns[i]+'0'); } print(_s); }
#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...