#define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define mpair make_pair #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; typedef long double ld; const ld epsylon = 1e-9; struct IndexTree { vector a; IndexTree(const vector&x ) { int n = (int)x.size(); int deg = 1; while(deg < n) deg *=2; a.resize(deg*2); for(int i=0;i=1;i--) a[i] = a[i*2] + a[i*2+1]; } void add_to(int idx,int val) { int n = (int)a.size(); int beg = n/2; int cur = beg + idx; while(cur >= 1) { a[cur] += val; cur /= 2; } } int get_val_to(int to) { if(to < 0) return 0; int n = (int)a.size(); int beg = n/2; int cur = beg + to; bool left = true; int res = a[cur]; while(cur >= 1) { if(!left) res += a[2*cur]; left = (cur%2 == 0); cur /= 2; } return res; } int get_val(int from,int to) { if (to < from) { return 0; } return get_val_to(to) - get_val_to(from-1); } int get_first_after(int i, int val) { val += get_val_to(i-1); int c = 1; int from = 0; int br = a.size() / 2; int to = br-1; int total = a[c]; int len = br; while (len > 1) { if (a[c*2] >= val) { c *= 2; to = to - len/2; } else { val -= a[c*2]; c = c*2 + 1; } len /= 2; } return to; /*int c = br + i; int from = i; int to = i; int total = a[c]; int len = 1; while (total < val) { if (c % 2 == 1) { c /= 2; from = from - len; } else { c /= 2; total = a[c]; to = to + len; } len*=2; } total = a[c]; val += get_val(from, i - 1); while (len > 1) { if (a[c*2] >= val) { total -= a[c*2+1]; c = c*2; to = to - len/2; } else { val -= a[c*2]; c = c*2 + 1; } len /= 2; } return to;*/ } }; int main() { freopen("lbulbs.in","r",stdin); freopen("lbulbs.out","w",stdout); int n, m; cin >> n >> m; vector a(n, -1); vector b(n,0); for (int i =0 ;i= k) { ci = it.get_first_after(ci + 1, k); } else { int u = k - temp; ci = it.get_first_after(0, u); } } else { ci = it.get_first_after(0, k); } } for (int i=0;i