QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#805877#2204. BorderInvincibleAC ✓884ms329572kbC++232.2kb2024-12-08 19:16:292024-12-08 19:16:29

Judging History

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

  • [2024-12-08 19:16:29]
  • 评测
  • 测评结果:AC
  • 用时:884ms
  • 内存:329572kb
  • [2024-12-08 19:16:29]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <ctime>
#include <random>
#include <cassert>
#include <numeric>
#include <cmath>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int, int>
#define fi first
#define se second
#define MP make_pair
#define ep emplace
#define eb emplace_back
#define pli pair<ll, int>
//#define int long long
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
#include <ext/pb_ds/assoc_container.hpp>
typedef double db;
typedef long double ldb;
typedef long long ll;
//typedef __int128 lll;
typedef unsigned long long ull;
typedef unsigned int ui;
using namespace std;
using namespace __gnu_pbds;
bool Mbe;

//char buf[1<<20],*p1,*p2;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin), p1 == p2) ? 0 : *p1++)
int read() {
	int s = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') f ^= (c == '-'), c = getchar();
	while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
	return f ? s : -s;
}
template<typename T>void chkmax(T&x,const T&y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,const T&y){if(x>y)x=y;}

const int N=1000055,B=45;
ll seed,Ans,tot,val[N];
int n,s[N],sz[N*B],tr[N*B][2],pos[N],kmp[N],tmp[60],ans[60];

bool Med;
signed main() {
	fprintf(stderr,"%.3lfMb\n",(&Mbe-&Med)/1024./1024.);
	n=read(),seed=read();
	rep(i,1,n)s[i]=(seed=(seed*13331+23333)%1000000007)&1;
	per(i,n,1){
		ll now=0;
		rep(j,i,i+B-1){
			now=now<<1|s[j];
		}
		val[i]=now;
	}
	per(i,n,1){
		memset(ans,0,sizeof ans);
		int lim=min(n-i+1,B),now=0;
		int t=0;
		rep(j,i,i+lim-1)tmp[++t]=s[j];
		kmp[1]=0;
		for(int j=2,k=0;j<=t;j++){
			while(k&&s[i+k]!=s[i+j-1])k=kmp[k];
			kmp[j]=(k+=(s[i+k]==s[i+j-1]));
		}
		rep(j,i,i+lim-1){
			if(!tr[now][s[j]])tr[now][s[j]]=++tot;
			now=tr[now][s[j]];
			pos[j]=now;
			ans[j-i+1]+=sz[now];
			if(kmp[j-i+1])ans[kmp[j-i+1]]-=sz[now];
		}
		rep(j,i,i+lim-1)sz[pos[j]]++;
		rep(j,1,lim)Ans+=(ll)j*ans[j];
	}
	printf("%lld\n",Ans);
	return 0;
}

Details

Test #1:

score: 100
Accepted
time: 0ms
memory: 10124kb

Test #2:

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

Test #3:

score: 0
Accepted
time: 2ms
memory: 10032kb

Test #4:

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

Test #5:

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

Test #6:

score: 0
Accepted
time: 67ms
memory: 48724kb

Test #7:

score: 0
Accepted
time: 71ms
memory: 44600kb

Test #8:

score: 0
Accepted
time: 44ms
memory: 46628kb

Test #9:

score: 0
Accepted
time: 51ms
memory: 48716kb

Test #10:

score: 0
Accepted
time: 59ms
memory: 44520kb

Test #11:

score: 0
Accepted
time: 66ms
memory: 46680kb

Test #12:

score: 0
Accepted
time: 51ms
memory: 48676kb

Test #13:

score: 0
Accepted
time: 776ms
memory: 329008kb

Test #14:

score: 0
Accepted
time: 790ms
memory: 327316kb

Test #15:

score: 0
Accepted
time: 884ms
memory: 329260kb

Test #16:

score: 0
Accepted
time: 813ms
memory: 328676kb

Test #17:

score: 0
Accepted
time: 858ms
memory: 328920kb

Test #18:

score: 0
Accepted
time: 796ms
memory: 328312kb

Test #19:

score: 0
Accepted
time: 801ms
memory: 327852kb

Test #20:

score: 0
Accepted
time: 799ms
memory: 328576kb

Test #21:

score: 0
Accepted
time: 749ms
memory: 328376kb

Test #22:

score: 0
Accepted
time: 818ms
memory: 328276kb

Test #23:

score: 0
Accepted
time: 781ms
memory: 327360kb

Test #24:

score: 0
Accepted
time: 834ms
memory: 329040kb

Test #25:

score: 0
Accepted
time: 806ms
memory: 328940kb

Test #26:

score: 0
Accepted
time: 834ms
memory: 327772kb

Test #27:

score: 0
Accepted
time: 776ms
memory: 328236kb

Test #28:

score: 0
Accepted
time: 854ms
memory: 328228kb

Test #29:

score: 0
Accepted
time: 796ms
memory: 328820kb

Test #30:

score: 0
Accepted
time: 826ms
memory: 328332kb

Test #31:

score: 0
Accepted
time: 838ms
memory: 327772kb

Test #32:

score: 0
Accepted
time: 804ms
memory: 328228kb

Test #33:

score: 0
Accepted
time: 811ms
memory: 328460kb

Test #34:

score: 0
Accepted
time: 759ms
memory: 329140kb

Test #35:

score: 0
Accepted
time: 815ms
memory: 328884kb

Test #36:

score: 0
Accepted
time: 783ms
memory: 327720kb

Test #37:

score: 0
Accepted
time: 806ms
memory: 328548kb

Test #38:

score: 0
Accepted
time: 803ms
memory: 327840kb

Test #39:

score: 0
Accepted
time: 825ms
memory: 327724kb

Test #40:

score: 0
Accepted
time: 749ms
memory: 327432kb

Test #41:

score: 0
Accepted
time: 862ms
memory: 329156kb

Test #42:

score: 0
Accepted
time: 782ms
memory: 329368kb

Test #43:

score: 0
Accepted
time: 823ms
memory: 329128kb

Test #44:

score: 0
Accepted
time: 789ms
memory: 328224kb

Test #45:

score: 0
Accepted
time: 868ms
memory: 327832kb

Test #46:

score: 0
Accepted
time: 849ms
memory: 328104kb

Test #47:

score: 0
Accepted
time: 833ms
memory: 327228kb

Test #48:

score: 0
Accepted
time: 826ms
memory: 329572kb

Test #49:

score: 0
Accepted
time: 759ms
memory: 329292kb

Test #50:

score: 0
Accepted
time: 852ms
memory: 328624kb

Test #51:

score: 0
Accepted
time: 806ms
memory: 328468kb

Test #52:

score: 0
Accepted
time: 782ms
memory: 328668kb

Test #53:

score: 0
Accepted
time: 783ms
memory: 328452kb

Test #54:

score: 0
Accepted
time: 819ms
memory: 328668kb

Test #55:

score: 0
Accepted
time: 783ms
memory: 328432kb