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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| #include "iostream" #include "algorithm" #include "cstring" #include "cstdio" #include "cmath" #include "vector" #include "map" #include "set" #include "queue" using namespace std; #define MAXN 1000006
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedef long long ll; int n , m;
pii len[MAXN << 2] , ps[MAXN << 2] , lf[MAXN << 2] , rg[MAXN << 2];
void pu( int rt ) { len[rt] = ps[rt] = lf[rt] = rg[rt] = mp( 0 , 0 ); if( !lf[rt << 1].fi && !rg[rt << 1 | 1].fi ) return; if( lf[rt << 1].fi ) lf[rt] = lf[rt << 1]; else lf[rt] = lf[rt << 1 | 1]; if( rg[rt << 1 | 1].fi ) rg[rt] = rg[rt << 1 | 1]; else rg[rt] = rg[rt << 1]; if( rg[rt << 1].fi && lf[rt << 1 | 1].fi ) { pii L = rg[rt << 1] , R = lf[rt << 1 | 1]; if( L.se == 3 && R.se == 3 ) { len[rt] = mp( ( R.fi - L.fi ) / 2 , 0 ); ps[rt] = mp( ( R.fi + L.fi ) / 2 , 1 ); } else if( L.se == 3 ) { len[rt] = mp( ( R.fi - L.fi ) / 2 , ( R.fi + L.fi ) & 1 ); ps[rt] = mp( ( R.fi + L.fi ) / 2 + ( ( R.fi + L.fi ) & 1 ) , ( ( R.fi + L.fi ) & 1 ) ? ( R.se ^ 3 ) : 1 ); } else if( R.se == 3 ) { len[rt] = mp( ( R.fi - L.fi ) / 2 , ( R.fi + L.fi ) & 1 ); ps[rt] = mp( ( R.fi + L.fi ) / 2 , ( ( R.fi + L.fi ) & 1 ) ? ( L.se ^ 3 ) : 1 ); } else { len[rt] = mp( ( R.fi - L.fi ) / 2 , ( ( R.fi + L.fi ) & 1 ) || ( R.se == L.se ) ); ps[rt] = mp( ( R.fi + L.fi ) / 2 , ( R.fi + L.fi & 1 || R.se == L.se ) ? ( L.se ^ 3 ) : 1 ); } } if( len[rt << 1] >= len[rt] ) len[rt] = len[rt << 1] , ps[rt] = ps[rt << 1]; if( len[rt << 1 | 1] > len[rt] ) len[rt] = len[rt << 1 | 1] , ps[rt] = ps[rt << 1 | 1]; } void ins( int rt , int l , int r , pii p ) { if( l == r ) { if( lf[rt].fi ) lf[rt].se = rg[rt].se = 3 , len[rt] = mp( 0 , 0 ) , ps[rt] = mp( 0 , 0 ); else lf[rt] = rg[rt] = p , len[rt] = mp( 1 , 0 ) , ps[rt] = mp( l , p.se ^ 3 ); return; } int m = l + r >> 1; if( p.fi <= m ) ins( rt << 1 , l , m , p ); else ins( rt << 1 | 1 , m + 1 , r , p ); pu( rt ); } void era( int rt , int l , int r , pii p ) { if( l == r ) { if( lf[rt].se == p.se ) lf[rt] = rg[rt] = len[rt] = ps[rt] = mp( 0 , 0 ); else {
lf[rt].se -= p.se; rg[rt].se = lf[rt].se; ps[rt] = mp( l , lf[rt].se ^ 3 ) , len[rt] = mp( 1 , 0 ); } return; } int m = l + r >> 1; if( p.fi <= m ) era( rt << 1 , l , m , p ); else era( rt << 1 | 1 , m + 1 , r , p ); pu( rt ); }
pii lsj[MAXN];
void solve() { cin >> n >> m; char op[4]; int w; rep( i , 1 , m ) { scanf("%s",op); if( op[0] == 'E' ) { if( !lf[1].fi ) printf("%d %d\n",1,1) , lsj[i] = mp( 1 , 1 ) , ins( 1 , 1 , n , mp( 1 , 1 ) ); else { pii le = len[1] , pp = ps[1] , tf = lf[1] , tr = rg[1]; if( mp( tf.fi - 1 , (int)( tf.se != 3 ) ) >= le ) pp = mp( 1 , tf.se == 3 ? 1 : ( tf.se ^ 3 ) ) , le = mp( tf.fi - 1 , (int)( tf.se != 3 ) ); if( mp( n - tr.fi , (int)( tr.se != 3 ) ) > le ) pp = mp( n , tr.se == 3 ? 1 : ( tr.se ^ 3 ) ) , le = mp( n - tr.fi , (int)( tr.se != 3 ) ); lsj[i] = pp , ins( 1 , 1 , n , pp ); printf("%d %d\n",pp.fi,pp.se); } } else { int x; scanf("%d",&x); era( 1 , 1 , n , lsj[x] ); } } }
signed main() {
solve(); }
|