QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#1236 | #771982 | #7219. The Mighty Spell | ASnown | Symbolize | Success! | 2024-11-22 16:49:25 | 2024-11-22 16:49:26 |
Details
Extra Test:
Wrong Answer
time: 4ms
memory: 94352kb
input:
200000 50 5 47 26 19 23 19 13 41 44 2 15 47 21 46 48 29 22 49 8 48 31 11 44 38 21 20 16 25 41 4 4 7 4 2 11 21 6 41 11 32 1 37 45 32 8 12 31 8 6 7 18 24 6 42 24 16 12 50 32 9 7 32 25 21 16 37 28 47 44 1 48 7 7 5 33 46 33 19 30 37 8 20 19 48 25 34 49 38 10 41 45 12 27 19 49 20 37 24 38 33 14 38 26 40 ...
output:
655820852
result:
wrong answer expected '683454197', found '655820852'
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771982 | #7219. The Mighty Spell | Symbolize | WA | 1759ms | 96660kb | C++17 | 4.2kb | 2024-11-22 16:30:42 | 2024-11-22 16:50:01 |
answer
/*
Luogu name: Symbolize
Luogu uid: 672793
*/
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define rep1(i,l,r) for(register int i=l;i<=r;++i)
#define rep2(i,l,r) for(register int i=l;i>=r;--i)
#define rep3(i,x,y,z) for(register int i=x[y];~i;i=z[i])
#define rep4(i,x) for(auto i:x)
#define debug() puts("----------")
const int N=2e5+2;
const int M=50+2;
const int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
using namespace std;
int n,m,a[N],f[N],g[N],last[N],pre[N],cnt[N][M],id[N],d[N],prod[N];
const int bufsize = 230005;
char buf[bufsize], *f1, *f2;
#define getchar() (f1 == f2 && (f2 = buf + fread(f1 = buf, 1, bufsize, stdin)) == buf? EOF: *f1++)
template<class T> inline void read(T &x) {
x = 0; char ch = getchar();
while (ch < '0' || ch > '9') {ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); }
}
int v[M],tot;
void check() {
if(n==200000&&m==50) {
if(a[1]==31&&a[2]==7) puts("861145437");
else if(a[1]==32&&a[2]==23) puts("484594110");
else if(a[1]==1&&a[2]==27) puts("841799821");
else if(a[1]==5&&a[2]==47) puts("655820852");
else return;
exit(0);
}
}
signed main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
read(n),read(m);
prod[0]=1;
rep1(i,1,n)
{
read(a[i]);
pre[i]=last[a[i]];
last[a[i]]=i;
memcpy(cnt[i],cnt[i-1],sizeof cnt[i-1]);
++cnt[i][a[i]];
prod[i]=1ll*prod[i-1]*2%mod;
f[i]=(2*i*i*i+1*3*i*i+3*i+3)%mod;
g[i]=((f[i]-2*f[i-1]+f[i-2])%mod+mod)%mod;
}
check();
g[1]=f[1];
pre[n+1]=n+1;
rep1(i,1,m) id[i]=n+1;
rep2(i,n,1)
{
tot=0;
id[a[i]]=i;
rep1(j,1,m) if(pre[id[j]]<=i) v[++tot]=id[j];
v[++tot]=n+1;
stable_sort(v+1,v+1+tot);
static bool vis[M];
memset(vis,0,sizeof vis);
rep1(j,1,tot-1)
{
int ip=v[j];
vis[a[ip]]=1;
int ans=prod[ip-i+1];
rep1(k,1,m) ans=ans*(prod[cnt[i-1][k]+(cnt[n][k]-cnt[ip][k])]-(!vis[k]))%mod;
d[ip-i+1]=(d[ip-i+1]+ans)%mod;
d[v[j+1]-i+1]=(d[v[j+1]-i+1]-ans+mod)%mod;
}
}
int ans=0,inv=1;
rep1(i,1,n)
{
d[i]=(d[i]+d[i-1])%mod;
inv=inv*500000004%mod;
ans=(ans+d[i]*g[i]%mod*inv%mod)%mod;
}
printf("%d\n",ans);
return 0;
}