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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

【BZOJ】2120: 数颜色

發布時間:2023/11/27 生活经验 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【BZOJ】2120: 数颜色 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題解

練習一下帶修改莫隊

先按照左端點的塊排序,再按照右端點的塊排序,然后按照時間排序

每個修改操作存一下修改前這個位置的值就可以逆序操作了

代碼

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 10005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {res = 0;char c = getchar();T f = 1;while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}while(c >= '0' && c <= '9') {res = res * 10 + c - '0';c = getchar();}res *= f;
}
template<class T>
void out(T x) {if(x < 0) {x = -x;putchar('-');}if(x >= 10) {out(x / 10);}putchar('0' + x % 10);
}int N,M,S;
int c[1000005],res,ans[MAXN],op[MAXN],col[2][MAXN],tot,id[MAXN],a[MAXN],tmp[MAXN];
int p,q,x;
struct qry_node {int id,l,r,bl,br;friend bool operator <  (const qry_node &a,const qry_node &b) {if(a.bl != b.bl) return a.bl < b.bl;if(a.br != b.br) return a.br < b.br;return a.id < b.id;} 
}qry[MAXN];
void update_pos(int pos,int v) {if(c[pos] == 0 && c[pos] + v == 1) ++res;else if(c[pos] == 1 && c[pos] + v == 0) --res;c[pos] += v;
}
void Change(int t) {if(t > x) {for(int i = x + 1 ; i <= t ; ++i) {if(op[i]) {if(op[i] <= q && op[i] >= p) {update_pos(a[op[i]],-1);update_pos(col[1][i],1);}a[op[i]] = col[1][i];}}}else {for(int i = x ; i > t ; --i) {if(op[i]) {if(op[i] <= q && op[i] >= p) {update_pos(a[op[i]],-1);update_pos(col[0][i],1);}a[op[i]] = col[0][i];}}}x = t;
}
void Move(int l,int r) {while(q < r) {update_pos(a[++q],1);}while(p > l) {update_pos(a[--p],1);}while(q > r) {update_pos(a[q--],-1);}while(p < l) {update_pos(a[p++],-1);}
}
void Solve() {read(N);read(M);S = pow(N,2.0 / 3.0);int h = 0;for(int i = 1 ; i <= N ; ++i) {read(a[i]);tmp[i] = a[i];}for(int i = 1 ; i <= N ; i += S) {int r = min(i + S - 1,N);++h;for(int j = i ; j <= r ; ++j) {id[j] = h;}}char s[5];int l,r;for(int i = 1 ; i <= M ; ++i) {scanf("%s",s + 1);read(l);read(r);if(s[1] == 'Q') {qry[++tot] = (qry_node){i,l,r,id[l],id[r]};}else {op[i] = l;col[1][i] = r;col[0][i] = tmp[l];tmp[l] = r;}}sort(qry + 1,qry + tot + 1);x = 0,p = 1,q = 0;for(int i = 1 ; i <= tot ; ++i) {Change(qry[i].id);Move(qry[i].l,qry[i].r);ans[qry[i].id] = res;}for(int i = 1 ; i <= M ; ++i) {if(!op[i]) {out(ans[i]);enter;}}
}
int main() {
#ifdef ivorysifreopen("f1.in","r",stdin);
#endifSolve();return 0;
}

轉載于:https://www.cnblogs.com/ivorysi/p/10098733.html

總結

以上是生活随笔為你收集整理的【BZOJ】2120: 数颜色的全部內容,希望文章能夠幫你解決所遇到的問題。

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