Untitled
unknown
plain_text
9 months ago
2.9 kB
17
Indexable
// Thongriu
#include <bits/stdc++.h>
#define endl '\n'
#define maxn 100005
#define MAX 1000005
#define MOD 1000000007
#define TASK "test"
#define ll long long
using namespace std;
int n, q, t[maxn], v[maxn], cnt = 0, res = 0;
int a[maxn], b[maxn], x[maxn];
int dem[MAX], lab[MAX];
char c[maxn];
multiset<int> ms;
int whatsub(){
if(n <= 1000 && q <= 1000) return 1;
for(int i = 1; i <= n; i++)
if(t[i] > 1000000) return 5;
bool sub2 = 1, sub3 = 1;
for(int i = 1; i <= q; i++){
if(x[i] > 1000000) return 5;
if(a[i] != 1 || b[i] != 1000000) return 4;
if(c[i] == '-') sub2 = 0;
if(c[i] == '+') sub3 = 0;
}
if(sub2) return 2;
if(sub3) return 3;
return 4;
}
void xoasub1(int x){
auto it = ms.find(x);
if(it != ms.end()) ms.erase(it);
}
void themsub1(int x){
ms.insert(x);
}
void truyvansub1(int a, int b){
cnt = 0;
res = 0;
for(int x : ms)
if(x >= a && x <= b) v[++cnt] = x;
sort(v + 1, v + cnt + 1);
cnt = unique(v + 1, v + cnt + 1) - (v + 1);
for(int l = 1; l <= cnt;){
int r = l;
while(r <= cnt && v[r] + 1 == v[r + 1]) r++;
res = max(res, r - l + 1);
l = r + 1;
}
cout << res << "\n";
}
void sub1(){
for(int i = 1; i <= n; i++)
ms.insert(t[i]);
for(int i = 1; i <= q; i++){
if(c[i] == '+') themsub1(x[i]);
if(c[i] == '-') xoasub1(x[i]);
if(c[i] == '?') truyvansub1(a[i], b[i]);
}
}
int getroot(int u){
if(lab[u] < 0) return u;
return (lab[u] = getroot(lab[u]));
}
void join(int u, int v){
int x = getroot(u), y = getroot(v);
if(x == y) return;
if(lab[x] > lab[y]) swap(x, y);
lab[x] += lab[y];
res = max(res, -lab[x]);
lab[y] = x;
}
void sub2(){
memset(lab, -1, sizeof(lab));
for(int i = 1; i <= n; i++){
dem[t[i]]++;
if(dem[t[i] - 1] > 0) join(t[i], t[i] - 1);
if(dem[t[i] + 1] > 0) join(t[i], t[i] + 1);
}
for(int i = 1; i <= q; i++){
if(c[i] == '+'){
dem[x[i]]++;
if(dem[x[i] - 1] > 0) join(x[i], x[i] - 1);
if(dem[x[i] + 1] > 0) join(x[i], x[i] + 1);
}
else cout << res << "\n";
}
}
int main()
{
ios_base:: sync_with_stdio(0);
cin.tie(nullptr);
if(fopen(TASK".inp","r")){
freopen(TASK".inp","r",stdin);
freopen(TASK".ans","w",stdout);
}
cin >> n >> q;
for(int i = 1; i <= n; i++)
cin >> t[i];
for(int i = 1; i <= q; i++){
cin >> c[i];
if(c[i] == '+' || c[i] == '-') cin >> x[i];
else cin >> a[i] >> b[i];
}
int sub = whatsub();
sub1();
// else if(sub == 2) sub2();
}
Editor is loading...
Leave a Comment