1. 程式人生 > >牛客OI周賽6-提高組 B 踐踏

牛客OI周賽6-提高組 B 踐踏

踐踏

思路:

如果k不為0, 那麼就是對k取模意義下的區間更新, 單點查詢

否則, 就是普通的區間更新, 單點查詢

程式碼:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define
pb push_back #define ls rt<<1, l, m #define rs rt<<1|1, m+1, r #define ULL unsigned LL #define pll pair<LL, LL> #define pli pair<LL, int> #define pii pair<int, int> #define piii pair<pii, int> #define mem(a, b) memset(a, b, sizeof(a)) #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define
fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout); //head const int N = 2e4 + 10; int bit[N], up; vector<int> vc; piii a[N]; void add(int x, int a) { while(x <= up) bit[x] += a, x += x&-x; } int sum(int x) { int res = 0; while(x) res += bit[x], x -= x&-x;
return res; } int main() { int n, k, op, l, r; scanf("%d %d", &n, &k); if(n == 0) return 0*puts("fafa"); if(k) { up = k; for (int i = 1; i <= n; i++) { scanf("%d %d", &op, &l); if(op == 1) { scanf("%d", &r); if(r - l + 1 >= k) { add(1, 1), add(k+1, -1); continue; } (l %= k) += 1; (r %= k) += 1; if(l <= r) add(l, 1), add(r+1, -1); else add(1, 1), add(r+1, -1), add(l, 1), add(k+1, -1); } else if(op == 2) { scanf("%d", &r); if(r - l + 1 >= k) { add(1, -1), add(k+1, 1); continue; } (l %= k) += 1; (r %= k) += 1; if(l <= r) add(l, -1), add(r+1, 1); else add(1, -1), add(r+1, 1), add(l, -1), add(k+1, 1); } else { printf("%d\n", sum(l%k + 1)); } } } else { up = 2*n; for (int i = 1; i <= n; i++) { scanf("%d %d", &a[i].se, &a[i].fi.fi); vc.pb(a[i].fi.fi); if(a[i].se <= 2) { scanf("%d", &a[i].fi.se); vc.pb(a[i].fi.se); } } sort(vc.begin(), vc.end()); vc.erase(unique(vc.begin(), vc.end()), vc.end()); for (int i = 1; i <= n; i++) { if(a[i].se == 1) { l = lower_bound(vc.begin(), vc.end(), a[i].fi.fi) - vc.begin() + 1; r = lower_bound(vc.begin(), vc.end(), a[i].fi.se) - vc.begin() + 1; add(l, 1); add(r+1, -1); } else if(a[i].se == 2) { l = lower_bound(vc.begin(), vc.end(), a[i].fi.fi) - vc.begin() + 1; r = lower_bound(vc.begin(), vc.end(), a[i].fi.se) - vc.begin() + 1; add(l, -1); add(r+1, 1); } else { int x = lower_bound(vc.begin(), vc.end(), a[i].fi.fi) - vc.begin() + 1; printf("%d\n", sum(x)); } } } return 0; }