日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

acdream 1157Segments cdq分治

發布時間:2025/4/14 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 acdream 1157Segments cdq分治 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接

?

#include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <complex> #include <cmath> #include <map> #include <set> #include <string> #include <queue> #include <stack> #include <bitset> using namespace std; #define pb(x) push_back(x) #define ll long long #define mk(x, y) make_pair(x, y) #define lson l, m, rt<<1 #define mem(a) memset(a, 0, sizeof(a)) #define rson m+1, r, rt<<1|1 #define mem1(a) memset(a, -1, sizeof(a)) #define mem2(a) memset(a, 0x3f, sizeof(a)) #define rep(i, n, a) for(int i = a; i<n; i++) #define fi first #define se second typedef complex <double> cmx; typedef pair<int, int> pll; const double PI = acos(-1.0); const double eps = 1e-8; const int mod = 1e9+7; const int inf = 1061109567; const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; const int maxn = 1e5+5; int v[maxn*2], n, b[maxn], cnt, num, sum[maxn*2], ans[maxn]; struct node {int l, r, id, val; }a[maxn]; bool cmp1(const node& lhs, const node& rhs) {return lhs.id < rhs.id; } bool cmp2(const node& lhs, const node& rhs) {if(lhs.r != rhs.r)return lhs.r > rhs.r;if(lhs.l != rhs.l)return lhs.l < rhs.l;return lhs.id < rhs.id; } int lowbit(int x) {return x&(-x);} void update(int x, int val) {while(x <= cnt) {sum[x] += val;x += lowbit(x);} } int query(int x) {int ret = 0;while(x) {ret += sum[x];x -= lowbit(x);}return ret; } void cdq(int l, int r) {if(l == r) return ;int m = l+r>>1;cdq(l, m);cdq(m+1, r);sort(a+l, a+1+r, cmp2);for(int i = l; i <= r; i++) {if(a[i].id <= m && a[i].val)update(a[i].l, a[i].val);if(a[i].id > m && !a[i].val)ans[a[i].id] += query(a[i].l);}for(int i = l; i <= r; i++)if(a[i].id <= m && a[i].val)update(a[i].l, -a[i].val);} void solve() {mem(ans);mem(sum);sort(v, v+cnt);cnt = unique(v, v+cnt)-v;for(int i = 1; i <= n; i++) {a[i].l = lower_bound(v, v+cnt, a[i].l)-v+1;a[i].r = lower_bound(v, v+cnt, a[i].r)-v+1;}cdq(1, n);sort(a+1, a+1+n, cmp1);for(int i = 1; i <= n; i++) {if(!a[i].val)printf("%d\n", ans[i]);} } int main() {int x;while(~scanf("%d", &n)) {cnt = num = 0;for(int i = 1; i <= n; i++) {char ch[1];scanf("%s", ch);a[i].id = i;if(ch[0] == 'C') {scanf("%d", &x);a[i].l = a[b[x]].l;a[i].r = a[b[x]].r;a[i].val = -1;} else {scanf("%d%d", &a[i].l, &a[i].r);v[cnt++] = a[i].l;v[cnt++] = a[i].r;if(ch[0] == 'D') {b[++num] = i;a[i].val = 1;} else {a[i].val = 0;}}}solve();}return 0; }

?

轉載于:https://www.cnblogs.com/yohaha/p/5701902.html

總結

以上是生活随笔為你收集整理的acdream 1157Segments cdq分治的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。