QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#332907#7877. Balanced ArrayWRuperDWA 1ms10000kbC++142.6kb2024-02-19 16:25:442024-02-19 16:25:45

Judging History

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

  • [2024-02-19 16:25:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:10000kb
  • [2024-02-19 16:25:44]
  • 提交

answer

// Problem:  Balanced Array
// URL: https://vjudge.net/problem/QOJ-7877
// Writer: WRuperD
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int mininf = 1e9 + 7;
#define int long long
#define pb emplace_back
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void write(int x){if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0');}
#define put() putchar(' ')
#define endl puts("")
#define ull unsigned long long
const int MAX = 2e6 + 10;

inline int fuckyouread(){
	char ch = getchar();
	while(!((ch >= '0' and ch <= '9') or (ch <= 'Z' and ch >= 'A') or (ch <= 'z' and ch >= 'a'))){
		ch = getchar();
	}
	int x = 0;
	while(((ch >= '0' and ch <= '9') or (ch <= 'Z' and ch >= 'A') or (ch <= 'z' and ch >= 'a'))){
		if(ch >= '0' and ch <= '9'){
			x = x * 62 + ch - '0';
		}else if(ch >= 'A' and ch <= 'Z'){
			x = x * 62 + ch - 'A' + 36; 
		}else{
			x = x * 62 + ch - 'a' + 10;
		}
		ch = getchar();
	}
	return x;
}

ull a[MAX];

ull base = 131;
ull hsh[MAX];
ull pre[MAX];
__int128 pre2[MAX], hsh2[MAX], base2 = 13331;
__int128 mod = 212370440130137957ll;

ull gethsh(int l, int r){
	return (hsh[r] - hsh[l - 1] * pre[r - l + 1]);
}

ull gethsh2(int l, int r){
	return (hsh2[r] - hsh2[l - 1] * pre2[r - l + 1] % mod + mod) % mod;
}
int mk[MAX];

void solve(){
	int n = read();
	for(int i = 1; i <= n; i++){
		a[i] = fuckyouread();
	}
	pre[0] = 1;
	for(int i = 1; i <= n; i++){
		pre[i] = pre[i - 1] * base;
	}
	pre2[0] = 1;
	for(int i = 1; i <= n; i++){
		pre2[i] = pre2[i - 1] * base2 % mod;
	}
	for(int i = 1; i <= n; i++){
		hsh[i] = hsh[i - 1] * base + a[i];
	}
	for(int i = 1; i <= n; i++){
		hsh2[i] = hsh2[i - 1] * base2 % mod + a[i];
		hsh2[i] %= mod; 
	}
	for(int i = 1; i <= n / 2 + 1; i++){
		int l = 2 * i + 1, r = n;
		int ans = l - 1;
		while(l <= r){
			int mid = (l + r) >> 1;
			if(gethsh(1, mid - 2 * i) + gethsh(2 * i + 1, mid) == (ull)(2) * gethsh(i + 1, mid - i) and (gethsh2(1, mid - 2 * i) + gethsh2(2 * i + 1, mid) % mod) == (2 * gethsh2(i + 1, mid - i))){
				l = mid + 1;
				ans = mid;
			}else{
				r = mid - 1;
			}
		}
		if(2 * i + 1 <= ans){
			mk[2 * i + 1]++, mk[ans + 1]--;
		}
	}
	int now = 0;
	for(int i = 1; i <= n; i++){
		now += mk[i];
		if(now){
			putchar('1');
		}else{
			putchar('0');
		}
	}
}

signed main(){
	int t = 1;
	while(t--)	solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 9692kb

input:

3
1 2 3

output:

001

result:

ok single line: '001'

Test #2:

score: 0
Accepted
time: 0ms
memory: 9680kb

input:

9
1 2 3 2 5 4 3 8 5

output:

001010111

result:

ok single line: '001010111'

Test #3:

score: 0
Accepted
time: 0ms
memory: 9748kb

input:

9
1C 3f 4S 3h 88 6x 4W d1 8c

output:

001010111

result:

ok single line: '001010111'

Test #4:

score: 0
Accepted
time: 1ms
memory: 9972kb

input:

49
71FjQ 71FzG 71FjR 71FjG 71FjS 71F3G 71FjT 71ENG 71FjU 71ExG 71FzG 71Fko 71FjW 71FOM 71FPm 71FzG 71FPO 71FP9 71FzG 71Fkc 71FzG 7AXBr 71FPH 8nKLh 71Fk2 71FzG 71FkK 4AGIE 71Fk9 6EfCL 71FPN 71FjJ 71FPb 7H3TC 71Gks 71FzG 71FPI 71FzG 6Oayg 71FPc 71FPw 71FPN 71Fkm 71FPK 71FPK 6Az4J 71FPI 71FzG 71Fke

output:

0000111111001000000000001000000000110000100000001

result:

ok single line: '0000111111001000000000001000000000110000100000001'

Test #5:

score: 0
Accepted
time: 1ms
memory: 9688kb

input:

48
4LZe2 4LZt4 4LZI6 4LZX8 4LZtY 4LZe2 4LZtX 4LZe2 4LYYd 4LYZ2 4LYZy 4LZe2 4LZtG 4LZtT 4LZe2 4LYtm 6g6ce 4LZe2 4LYYI 8MRDV 4LZu3 6tLzK 4WUft 7EU0p 5FVal 4LZe2 4LZe2 4LZu8 4LZe2 4LXtE 7KcGm 4LYXX 4LYYn 5v3aX 4LZtC 4LZu3 4LZe2 4LYYI 4LZtQ 4TSBp 4LYYB 4LZe2 4MatY 4LYYi 57PgU axOxK 6zQCA 4LZe2

output:

001100000000001100000000000011100000000000001110

result:

ok single line: '001100000000001100000000000011100000000000001110'

Test #6:

score: 0
Accepted
time: 1ms
memory: 9688kb

input:

50
6NIbv 6ZUpG 7c6DR 7oiS2 6NIbv 6NIbv 8Uivo 6NIbv 6NIqD 6NIbv 6NHWa 6NHVS 6NIrs 6NIrB 6NIqy 84jAs 6NIFL 6BvXk 6NHW0 6NIqV 6NIqZ 6NIr3 6NHGf 6NHVY 6NIrC 6NHVT 6NIqp 6NIbv 6NIFB 6NHW8 4TPq0 6NHVq 6NJa1 6NIbv 6NIbv 6NHVG 6NHGv 6Bwsa 6pke7 6NIbv 6NIGt 6Bwsq 6piID 6d6ZU 6NIrk 6NIr4 6NHVR 5c7Qh 6NIrv 6NHVQ

output:

00110000000000001100001000001000100011101111000000

result:

ok single line: '00110000000000001100001000001000100011101111000000'

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 10000kb

input:

47
6vtDV 6vtTo 6vu8v 6vtE6 6vuD5 6vtDE 6vtEj 6vtDz 6vvCf 6vtnU 4Mrgd 5NjpO 6vtEH 6vu99 6vtDd 6vxl6 6vtDw 6vu8V 5RBQQ 8XwN1 6vtTo 5K2nw 7UTxg 6vu8U 6vu94 6vu9o 6vtTo 6vu8W 6vu9u 6vtTo 6vB2h 6vtnE 6vu9l 5dK3A 6vtE8 6vtDA 5dK3L bpzGE 6vtEh 4YB6W 9kirr 6vuEa 6vuDP 6vtTo 6vu99 6vu8H 6vtTo

output:

00001000110010110000000000000011100011111000000

result:

wrong answer 1st lines differ - expected: '00001000110010110000000000000011110011111110000', found: '00001000110010110000000000000011100011111000000'