QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#724726 | #1964. Stock Price Prediction | ucup-team3161# | WA | 515ms | 32480kb | C++17 | 1.6kb | 2024-11-08 14:45:45 | 2024-11-08 14:45:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define mid ((l+r)/2)
const int N=1e6+5,MOD=1e9+7,base=998244353;
int n,m,hs,s,a[N],b[N],dsa[N],dsb[N],pw[N];bool fl;
struct Seg {int vl,vl1;}sg[N*4];
void work(int ds[]) {sort(ds+1,ds+ds[0]+1);ds[0]=unique(ds+1,ds+ds[0]+1)-ds-1;}
int id(int ds[],int x) {return lower_bound(ds+1,ds+ds[0]+1,x)-ds;}
void pu(int p)
{
sg[p].vl=(1ll*sg[p*2].vl*pw[sg[p*2+1].vl1]+sg[p*2+1].vl)%MOD;
sg[p].vl1=sg[p*2].vl1+sg[p*2+1].vl1;
}
void upd(int p,int l,int r,int x,int vl)
{
if(l==r) {sg[p].vl=(1ll*sg[p].vl*base+vl)%MOD;++sg[p].vl1;return;}
if(x<=mid) upd(p*2,l,mid,x,vl);else upd(p*2+1,mid+1,r,x,vl);pu(p);
}
void upd1(int p,int l,int r,int x,int vl)
{
if(l==r) {--sg[p].vl1;sg[p].vl=(sg[p].vl+1ll*(MOD-vl)*pw[sg[p].vl1])%MOD;return;}
if(x<=mid) upd1(p*2,l,mid,x,vl);else upd1(p*2+1,mid+1,r,x,vl);pu(p);
}
int main()
{
scanf("%d %d",&n,&m);
for(int i=1;i<=n;++i) scanf("%d",&a[i]),dsa[++dsa[0]]=a[i];
for(int i=1;i<=m;++i) scanf("%d",&b[i]),dsb[++dsb[0]]=b[i];
work(dsa);work(dsb);
for(int i=1;i<=n;++i) a[i]=id(dsa,a[i]);
for(int i=1;i<=m;++i) b[i]=id(dsb,b[i]);
pw[0]=1;for(int i=1;i<=n;++i) pw[i]=1ll*pw[i-1]*base%MOD;
for(int i=1,t;i<=n;++i)
{
t=0;
for(int j=1;j<=n;++j) if(a[i]<a[j] || (a[i]==a[j] && i<j)) ++t;
hs=(hs+1ll*pw[t]*i)%MOD;
}
for(int i=0;i<n;++i) s=(s+pw[i])%MOD;
for(int i=1;i<=m;++i)
{
upd(1,1,dsb[0],b[i],i);
if(i>n) upd1(1,1,dsb[0],b[i-n],i-n);
if(i>=n && sg[1].vl==(hs+1ll*s*(i-n))%MOD) printf("%d ",i-n+1),fl=1;
}
if(!fl) puts("0");
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 515ms
memory: 32440kb
input:
10000 1000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok single line: '1 2 3 4 5 6 7 8 9 10 11 12 13 ...97 989998 989999 990000 990001 '
Test #2:
score: -100
Wrong Answer
time: 479ms
memory: 32480kb
input:
10000 1000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...
output:
1 2 10002 20002 30002 40002 50002 60002 70002 80002 90002 100002 110002 120002 130002 140002 150002 160002 170002 180002 190002 200002 210002 220002 230002 240002 250002 260002 270002 280002 290002 300002 310002 320002 330002 340002 350002 360002 370002 380002 390002 400002 410002 420002 430002 4400...
result:
wrong answer 1st lines differ - expected: '2 10002 20002 30002 40002 5000...002 950002 960002 970002 980002', found: '1 2 10002 20002 30002 40002 50...02 950002 960002 970002 980002 '