QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#656853#9483. Maximize Arrayucup-team4717#WA 1ms9804kbC++172.1kb2024-10-19 13:47:162024-10-19 13:47:16

Judging History

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

  • [2024-10-19 13:47:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9804kb
  • [2024-10-19 13:47:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x),putch(' '),write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=3e5+5,base=1000249,mod=998244353;
inline int Mod(int x){return x>=mod?x-mod:x;} 
int n,k;
int s[N];
int Hash[N],P[N];
int calc(int l,int r){return Mod(Hash[r]+mod-1ll*P[r-l+1]*Hash[l-1]%mod);}
bool check(int l1,int r1,int l2,int r2){return calc(l1,r1)==calc(l2,r2);}
bool cmp(int l1,int r1,int l2,int r2){
	int l=0,r=min(r1-l1+1,r2-l2+1);
	if(check(l1,l1+r-1,l2,l2+r-1))return r1-l1>r2-l2;
	while(l<r){
		int mid=((l+r+1)>>1);
		if(check(l1,l1+mid-1,l2,l2+mid-1))l=mid;
		else r=mid-1;
	}
	return s[l1+l]>s[l2+l];
}
signed main(){
	read(n,k);
	for(int i=1;i<=n;i++)read(s[i]);
	for(int i=P[0]=1;i<=n;i++)P[i]=1ll*base*P[i-1]%mod;
	for(int i=1;i<=n;i++)Hash[i]=Mod(1ll*base*Hash[i-1]%mod+s[i]);
	for(int i=1;i<=n;){
		if(i+k<=n){
			int best=i;
			for(int j=1;i+j*k<=n+1;j++){
				if(cmp(i+j*k,n,best,n))best=i+j*k;
			}
			if(best==i)write(s[i]),putch(' '),i++;
			else i=best;
		}else write(s[i]),putch(' '),i++;
	}
	flush();
	return 0;
}

詳細信息

Test #1:

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

input:

9 3
1 2 3 4 1 2 3 4 1

output:

4 4 1 

result:

ok 3 tokens

Test #2:

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

input:

6 1
1 6 4 2 3 5

output:

6 5 

result:

ok 2 tokens

Test #3:

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

input:

6 5
6 5 4 3 2 1

output:

6 5 4 3 2 1 

result:

ok 6 tokens

Test #4:

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

input:

1392 5
915 798 656 1252 1170 691 1298 205 254 1334 622 1090 1081 617 365 477 362 1306 35 432 744 144 1277 259 80 410 317 983 916 1089 700 1030 135 156 1102 945 1021 63 251 1173 485 1261 1305 219 1190 151 142 288 795 984 1324 417 1235 1295 374 1091 434 596 553 1298 244 1179 115 767 973 315 603 180 10...

output:

1385 1386 1388 1296 1065 1332 1139 288 828 749 1214 1089 

result:

ok 12 tokens

Test #5:

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

input:

1235 294
496 705 855 832 681 885 857 35 617 356 164 22 982 1095 448 671 532 600 906 781 328 288 424 1162 505 170 804 1131 856 658 151 636 828 876 892 293 302 63 846 1140 528 1231 332 910 458 1208 481 1107 1121 928 579 1061 465 633 1171 1044 983 62 40 707 573 899 967 416 1208 31 1187 119 1035 1180 30...

output:

1057 731 575 815 1094 1051 979 737 338 100 236 125 1185 163 265 336 1 953 716 258 378 494 1131 539 771 762 377 52 332 463 1079 1217 937 425 1106 584 218 761 658 1124 428 1158 1213 506 978 181 95 380 704 458 346 1004 371 582 260 569 64 181 4 

result:

ok 59 tokens

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 9736kb

input:

1731 3
1304 1034 1285 402 1110 691 1544 1520 57 657 860 806 278 539 112 347 323 1170 757 769 841 1364 412 68 596 11 654 1523 1536 87 59 644 1165 1421 1095 796 684 463 769 296 409 1510 1595 645 1260 115 939 1054 857 89 1660 1473 355 1586 1219 1375 673 909 430 246 1273 497 955 1408 1593 1475 142 315 1...

output:

1731 1722 1709 1455 1211 1215 

result:

wrong answer 2nd words differ - expected: '1728', found: '1722'