1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | /// Raihan Ruhin /// CSE, Jahangirnagar University. /// Dhaka-Bangladesh. /// id: raihanruhin (topcoder / codeforces / codechef / uva ), 3235 (lightoj) /// mail: raihanruhin@ (yahoo / gmail / facebook) /// blog: ruhinraihan.blogspot.com #include<bits/stdc++.h> using namespace std; #define SET(a) memset(a,-1,sizeof(a)) #define CLR(a) memset(a,0,sizeof(a)) #define PI acos(-1.0) #define MOD 1000000007 #define MX 100010 int l[MX], r[MX]; int main() { ios_base::sync_with_stdio(0);cin.tie(0); int tc,kk=1, n, q, lf, rg; while(cin>>n>>q) { if(!n && !q) return 0; for(int i=1;i<=n;i++) l[i]=i-1, r[i]=i+1; r[n]=0; while(q--) { cin>>lf>>rg; l[r[rg]] = l[lf]; r[l[lf]] = r[rg]; if(l[lf]) cout<<l[lf]<<" "; else cout<<"* "; if(r[rg]) cout<<r[rg]<<"\n"; else cout<<"*\n"; } cout<<"-\n"; } return 0; } |
Monday, 10 July 2017
Army Buddies (UVa 12356, UVaLive 5789, Regionals 2011 >> Latin America)
Subscribe to:
Posts (Atom)