QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#743186#4918. 染色yangryan0 0ms0kbC++142.0kb2024-11-13 18:31:382024-11-13 18:31:39

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 18:31:39]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-11-13 18:31:38]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

namespace IO {
	const int N = (1 << 21);
	char ibuf[N], *p1= ibuf, *p2 = ibuf;
	char obuf[N], *p3 = obuf, ch[100];
	#ifdef ONLINE_JUDGE
		#define getch() (p1 == p2 ? p2 = (p1 = ibuf) + fread(ibuf, 1, N, stdin), (p1 == p2 ? EOF : *p1++) : *p1++)
		inline void putch(const char& ch) {	((p3 - obuf) < N) ? (*p3++ = ch) : (fwrite(obuf, 1, p3 - obuf, stdout), p3 = obuf, *p3++ = ch); }
	#else
		#define getch() getchar()
		inline void putch(const char &ch) { putchar(ch); }
	#endif
	template <typename T> inline void read(T& x) {
		char ch = getch(); x = 0;
		while(!isdigit(ch)) ch = getch();
		while(isdigit(ch)) x = x * 10 + ch - 48, ch = getch();
	}
	template <typename T, typename ...Args> void read(T& x, Args& ...args) {
		read(x), read(args...);
	}
	inline void write(const char &x) {
		putch(x);
	}
	inline void write(const char *s) {
		for(const char *ch = s; *ch; ch++) putch(*ch);
	}
	template <typename T> inline void write(T x) { 
		int top(0);
		do ch[++top] = x % 10 + 48, x /= 10; while(x);
		while(top) putch(ch[top--]);
	}
	template <typename T, typename ...Args> void write(T x, Args ...args) {
		write(x), write(args...);
	}
	inline void flush() { fwrite(obuf, 1, p3 - obuf, stdout); p3 = obuf; }
	#undef getch
}
using IO::read; using IO::write; using IO::putch; using IO::flush;
const int N = 1e6 + 5;

int n, QWQ;
int lst[N], p[N][21];

signed main() {
//	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	
	read(n, QWQ);
	for(int i = 1, a; i <= n; i++) {
		read(a);
		p[i][0] = max(p[i - 1][0], lst[a]);
		for(int j = 1; p[i][j] = p[p[i][j - 1]][j - 1]; j++) ;
		lst[a] = i;
	}
	for(int l, r, ans; QWQ--; ) {
		read(l, r); 
		if(l == r) { write("0\n"); continue; }
		if(l > r) l ^= r ^= l ^= r;
		ans = (r - l) << 1;
		for(int i = 20; i >= 0; i--) if(p[r][i] >= l) r = p[r][i], ans -= (1 << i);
		write(ans, '\n');
	}
	flush();
	
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Dangerous Syscalls

Test #1:

score: 0
Dangerous Syscalls

input:

1000 1000
3 722 914 2141556875752121755
3 323 347 6433743606947304931
2 142 206 439
2 117 840 195
2 127 502 56
3 168 707 15142638115094015116
4 190 257
2 88 976 475
1 319 867 351
1 682 889 409
2 406 446 196
3 28 35 4899387534800369959
2 291 546 150
1 528 617 128
1 58 122 251
2 381 400 276
4 510 958
...

output:


result:


Subtask #2:

score: 0
Dangerous Syscalls

Test #11:

score: 0
Dangerous Syscalls

input:

300000 300000
1 237576 237663 1
3 16150 16208 9270412155482010138
2 175648 175692 1
4 190836 190849
4 199010 199097
1 73976 298801 1
3 89902 89939 6418828085116455990
3 55415 55461 12238963685511262676
3 119825 119875 8146944792877919309
3 135103 135158 218634681842812119
3 127261 127352 13291431184...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Dangerous Syscalls

Test #31:

score: 0
Dangerous Syscalls

input:

300000 300000
1 85444 86076 59
1 41150 41411 71
1 278698 279414 45
1 238445 239202 56
1 29965 29984 49
1 282953 283272 37
1 34668 35653 86
2 198587 198744 28
1 270855 271611 58
1 2130 2965 773
1 161601 162298 937
1 50299 50435 36
1 100759 101198 64
1 120208 120543 84
1 295293 295732 34
1 112185 1129...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%