Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 3263 Accepted Submission(s): 1299
node
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <bitset> 6 #include <vector> 7 #include <queue> 8 #include <stack> 9 #include <cmath> 10 #include <list> 11 #include <set> 12 #include <map> 13 #define rep(i,a,b) for(int i = a;i <= b;++ i) 14 #define per(i,a,b) for(int i = a;i >= b;-- i) 15 #define mem(a,b) memset((a),(b),sizeof((a))) 16 #define FIN freopen("in.txt","r",stdin) 17 #define FOUT freopen("out.txt","w",stdout) 18 #define IO ios_base::sync_with_stdio(0),cin.tie(0) 19 #define mid ((l+r)>>1) 20 #define ls (id<<1) 21 #define rs ((id<<1)|1) 22 using namespace std; 23 typedef long long LL; 24 typedef pair<int, int> PIR; 25 const int N = 50005; 26 struct Node{ 27 int sum, lazy; 28 }node[N*4]; 29 int T, n, m, op, x, y; 30 31 void pushUp(int id, int l, int r){ 32 node[id].sum = node[ls].sum+node[rs].sum; 33 } 34 void pushDown(int id, int l, int r){ 35 node[ls].sum = node[id].lazy*(mid-l+1); 36 node[rs].sum = node[id].lazy*(r-mid); 37 node[ls].lazy = node[id].lazy; 38 node[rs].lazy = node[id].lazy; 39 node[id].lazy = -1; 40 } 41 void build(int id, int l, int r){ 42 node[id].lazy = -1; 43 if(l == r){ 44 node[id].sum = 0; 45 return ; 46 } 47 build(ls, l, mid); 48 build(rs, mid+1, r); 49 pushUp(id, l, r); 50 } 51 void update(int id, int l, int r, int ql, int qr, int p){ 52 if(l == ql && r == qr){ 53 node[id].lazy = p; 54 node[id].sum = (r-l+1)*p; 55 return ; 56 } 57 if(node[id].lazy != -1) 58 pushDown(id, l, r); 59 if(qr <= mid) update(ls, l, mid, ql, qr, p); 60 else if(ql > mid) 61 update(rs, mid+1, r, ql, qr, p); 62 else{ 63 update(ls, l, mid, ql, mid, p); 64 update(rs, mid+1, r, mid+1, qr, p); 65 } 66 pushUp(id, l, r); 67 } 68 int query(int id, int l, int r, int ql, int qr){ 69 if(l == ql && r == qr){ 70 return node[id].sum; 71 } 72 if(node[id].lazy != -1) pushDown(id, l, r); 73 if(qr <= mid) return query(ls, l, mid, ql, qr); 74 else if(ql > mid) 75 return query(rs, mid+1, r, ql, qr); 76 else{ 77 return query(ls, l, mid, ql, mid)+query(rs, mid+1, r, mid+1, qr); 78 } 79 } 80 int main() 81 {IO; 82 //FIN; 83 cin >> T; 84 while(T--){ 85 cin >> n >> m; 86 build(1, 1, n); 87 rep(i, 1, m){ 88 cin >> op >> x >> y; 89 if(op == 1){ 90 x++; 91 int cnt = n-x+1-query(1, 1, n, x, n); 92 if(cnt == 0){ 93 cout << "Can not put any one." << endl; 94 continue; 95 } 96 cnt = min(cnt, y); 97 int low = x, high = n, ansl, ansr; 98 while(low <= high){ 99 int md = (low+high)>>1; 100 if(query(1, 1, n, x, md) < md-x+1){ 101 ansl = md; 102 high = md-1; 103 } 104 else{ 105 low = md+1; 106 } 107 } 108 low = x, high = n; 109 while(low <= high){ 110 int md = (low+high)>>1; 111 if(md-x+1-query(1, 1, n, x, md) >= cnt){ 112 ansr = md; 113 high = md-1; 114 } 115 else{ 116 low = md+1; 117 } 118 } 119 update(1, 1, n, ansl, ansr, 1); 120 cout << ansl-1 << " " << ansr-1 << endl; 121 } 122 else{ 123 x++; 124 y++; 125 int ans = query(1, 1, n, x, y); 126 update(1, 1, n, x, y, 0); 127 cout << ans << endl; 128 } 129 } 130 cout << endl; 131 } 132 return 0; 133 }