Submission #59853560


Source Code Expand

Copy
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define rep(i,x,y) for(register int i=x;i<=y;i++)
#define rep1(i,x,y) for(register int i=x;i>=y;--i)
#define int long long
#define fire signed
#define il inline
template<class T> il void print(T x) {
if(x<0) printf("-"),x=-x;
if (x > 9) print(x / 10);
putchar(x % 10 + '0');
}
template<class T> il void in(T &x) {
x = 0; char ch = getchar();
int f = 1;
while (ch < '0' || ch > '9') {if(ch=='-') f = -1; ch = getchar(); }
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define rep(i,x,y) for(register int i=x;i<=y;i++)
#define rep1(i,x,y) for(register int i=x;i>=y;--i)
#define int long long
#define fire signed
#define il inline
template<class T> il void print(T x) {
	if(x<0) printf("-"),x=-x;
	if (x > 9) print(x / 10);
	putchar(x % 10 + '0');
}
template<class T> il void in(T &x) {
    x = 0; char ch = getchar();
    int f = 1;
    while (ch < '0' || ch > '9') {if(ch=='-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); }
    x *= f;
}
int T=1;
int n,q;
const int N=5e5+10;
int fa[N],l[N],r[N];
int val[N];
int find(int x) {
	return x==fa[x]?x:fa[x]=find(fa[x]);
}
int cnt[N];
void solve() {
	in(n),in(q);
	rep(i,1,n) {
		fa[i]=i,val[i]=i;
		cnt[i]++;
		l[i]=r[i]=i;
	}
	while(q--) {
		int opt;
		in(opt);
		if(opt==1) {
			int x,c;
			in(x),in(c);
			int tx=find(x);
			int lst=l[tx]-1;
			cnt[val[tx]]-=(r[tx]-l[tx]+1);
			val[tx]=c;
			cnt[c]+=(r[tx]-l[tx]+1);
			if(lst>=1) {
				int txx=find(lst);
				if(val[txx]==c) {
					fa[tx]=txx;
					l[txx]=l[txx];
					r[txx]=r[tx];
					val[txx]=c;
				}
			}
			tx=find(x);
			int lst1=r[tx]+1;
			if(lst1<=n) {
				int tyy=find(lst1);
				if(val[tyy]==c) {
					fa[tx]=tyy;
					l[tyy]=l[tx];
					r[tyy]=r[tyy];
					val[tyy]=c;
				}
			}
		}else {
			int x;
			in(x);
			printf("%lld\n",cnt[x]);
		}
	}
}
fire main() {
	while(T--) {
		solve();
	}
	return false;
}

Submission Info

Submission Time
Task E - 1D Bucket Tool
User zhy091206
Language C++ 20 (gcc 12.2)
Score 450
Code Size 1699 Byte
Status AC
Exec Time 49 ms
Memory 23340 KB

Compile Error

Main.cpp: In function ‘void solve()’:
Main.cpp:36:13: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   36 |         rep(i,1,n) {
      |             ^
Main.cpp:8:37: note: in definition of macro ‘rep’
    8 | #define rep(i,x,y) for(register int i=x;i<=y;i++)
      |                                     ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 1
AC × 18
Set Name Test Cases
Sample sample_01.txt
All hand.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, sample_01.txt
Case Name Status Exec Time Memory
hand.txt AC 1 ms 3676 KB
random_01.txt AC 9 ms 3704 KB
random_02.txt AC 12 ms 3836 KB
random_03.txt AC 13 ms 3836 KB
random_04.txt AC 14 ms 3768 KB
random_05.txt AC 15 ms 23152 KB
random_06.txt AC 19 ms 23152 KB
random_07.txt AC 18 ms 23124 KB
random_08.txt AC 49 ms 23340 KB
random_09.txt AC 49 ms 23276 KB
random_10.txt AC 49 ms 23180 KB
random_11.txt AC 45 ms 23152 KB
random_12.txt AC 45 ms 23212 KB
random_13.txt AC 16 ms 5596 KB
random_14.txt AC 17 ms 5596 KB
random_15.txt AC 16 ms 5724 KB
random_16.txt AC 16 ms 5720 KB
sample_01.txt AC 1 ms 3636 KB


2025-03-05 (Wed)
18:12:02 +00:00