#include <iostream> #include <algorithm> #include <cstring> #include <string> #include <queue> #include <vector> #include <cstdio> using namespace std; typedef long long LL; const int N = 100010, INF = 2e9+10; LL a[N], n, k; LL cnt[N]; struct SegmT{ LL l, r; LL val; } tr[N * 4]; void upside(int p){ tr[p].val = min(tr[p * 2].val, tr[p * 2 + 1].val); } void build(LL p, LL l, LL r){ tr[p].l = l, tr[p].r = r; if (l == r) { tr[p].val = 0; return; } LL mid = (l + r) >> 1; build(p * 2, l, mid); build(p * 2 + 1, mid + 1, r); upside(p); } void change(LL p, LL x, LL v){ if (tr[p].l == tr[p].r){ tr[p].val = v; return; } LL mid = (tr[p].l + tr[p].r) >> 1; if (x <= mid) change(p * 2, x, v); else change(p * 2 + 1, x, v); upside(p); } LL ask(LL p, LL l, LL r, LL t){ if (tr[p].l == tr[p].r) { return tr[p].r; } LL mid = (tr[p].l + tr[p].r) >> 1; LL res = -1; if (l <= mid && r >= tr[p].l && tr[p * 2].val <= t){ res = ask(p * 2, l, r, t); } if( res == - 1 && r >= mid + 1 && l <= tr[p].r && tr[p * 2 + 1].val <= t){ res = ask(p * 2 + 1, l, r, t); } return res; } int main(){ cin >> k >> n; for (int i = 0; i < N * 4; i ++) tr[i].val = INF; build(1, 1, k); LL res = 0; for (int i = 0; i < n; i ++){ LL co, t; scanf("%lld %lld", &co, &t); LL p = (i % k) + 1; // 当前所取的p值! LL t1 = ask(1, p, k, co); if (t1 == -1){ LL t2 = ask(1, 1, p-1, co); if (t2 != -1){ cnt[t2] ++; res = max(res, cnt[t2]); change(1, t2, co + t); } } else{ cnt[t1] ++; res = max(res, cnt[t1]); change(1, t1, co + t); } } bool flag = false; for (int i = 1; i <= k; i ++){ if (!flag && cnt[i] == res) { printf("%lld", i-1); flag = true; } else if (cnt[i] == res) printf(" %lld", i-1); } return 0; } |