QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#120588#3276. 出题高手zhouhuanyi45 662ms48728kbC++113.2kb2023-07-06 22:40:002023-07-06 22:40:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 22:40:02]
  • 评测
  • 测评结果:45
  • 用时:662ms
  • 内存:48728kb
  • [2023-07-06 22:40:00]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#define N 1000000
#define inf 1e9
using namespace std;
int read()
{
    char c=0;
    int sum=0,f=1;
    while (c!='-'&&(c<'0'||c>'9')) c=getchar();
    if (c=='-') c=getchar(),f=-1;
    while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
    return sum*f;
}
long long gcd(long long a,long long b)
{
    if (!b) return a;
    return gcd(b,a%b);
}
struct reads
{
    int l,r,num;
};
struct rds
{
    long long a;
    int b;
    bool operator < (const rds &t)const
    {
	return a*t.b<b*t.a;
    }
};
rds ans[N+1],A[N+1],B[N+1];
int n,m,a[N+1],s[N+1],dque[N+1],top,dque2[N+1],top2,tong[N+1],length,tong2[N+1],length2,tong3[N+1],length3,tong4[N+1],length4,ps[N+1],ps2[N+1],ps3[N+1],ps4[N+1];
void solve(int l,int r,vector<reads>p)
{
    if (l==r||p.empty()) return;
    int mid=(l+r)>>1,minn=inf,maxn=-inf,sl=inf,sr=0;
    vector<reads>tA;
    vector<reads>tB;
    for (int i=0;i<p.size();++i)
	if (p[i].l<=mid&&mid+1<=p[i].r)
	    sl=min(sl,p[i].l),sr=max(sr,p[i].r);
    length=length2=length=length4=top=top2=0,A[mid+1]=(rds){-1,0},B[mid]=(rds){-1,0};
    for (int i=mid;i>=sl;--i)
    {
	A[i]=A[i+1];
	while (top&&s[dque[top]]<=s[i]) top--;
	while (top2&&s[dque2[top2]]>=s[i]) top2--;
	for (int j=1;j<=top;++j) A[i]=max(A[i],(rds){1ll*(s[i]-s[dque[j]])*(s[i]-s[dque[j]]),dque[j]-i});
	for (int j=1;j<=top2;++j) A[i]=max(A[i],(rds){1ll*(s[i]-s[dque2[j]])*(s[i]-s[dque2[j]]),dque2[j]-i});
	dque[++top]=i,dque2[++top2]=i;
    }
    top=top2=0;
    for (int i=mid+1;i<=sr;++i)
    {
	B[i]=B[i-1];
	while (top&&s[dque[top]]<=s[i]) top--;
	while (top2&&s[dque2[top2]]>=s[i]) top2--;
	for (int j=1;j<=top;++j) B[i]=max(B[i],(rds){1ll*(s[i]-s[dque[j]])*(s[i]-s[dque[j]]),i-dque[j]});
	for (int j=1;j<=top2;++j) B[i]=max(B[i],(rds){1ll*(s[i]-s[dque2[j]])*(s[i]-s[dque2[j]]),i-dque2[j]});
	dque[++top]=i,dque2[++top2]=i;
    }
    for (int i=mid;i>=sl;--i)
    {
	if (s[i]<minn) minn=s[i],tong[++length]=i;
	if (s[i]>maxn) maxn=s[i],tong2[++length2]=i;
	ps[i]=length,ps2[i]=length2;
    }
    minn=inf,maxn=-inf;
    for (int i=mid+1;i<=sr;++i)
    {
	if (s[i]<minn) minn=s[i],tong3[++length3]=i;
	if (s[i]>maxn) maxn=s[i],tong4[++length4]=i;
	ps3[i]=length3,ps4[i]=length4;
    }
    for (int i=0;i<p.size();++i)
    {
	if (p[i].r<=mid) tA.push_back(p[i]);
	else if (p[i].l>=mid+1) tB.push_back(p[i]);
	else
	{
	    ans[p[i].num]=max(A[p[i].l],B[p[i].r]);
	    for (int j=1;j<=ps[p[i].l];++j)
		for (int k=1;k<=ps4[p[i].r];++k)
		    ans[p[i].num]=max(ans[p[i].num],(rds){1ll*(s[tong4[k]]-s[tong[j]])*(s[tong4[k]]-s[tong[j]]),tong4[k]-tong[j]});
	    for (int j=1;j<=ps2[p[i].l];++j)
		for (int k=1;k<=ps3[p[i].r];++k)
		    ans[p[i].num]=max(ans[p[i].num],(rds){1ll*(s[tong3[k]]-s[tong2[j]])*(s[tong3[k]]-s[tong2[j]]),tong3[k]-tong2[j]});
	}
    }
    solve(l,mid,tA),solve(mid+1,r,tB);
    return;
}
int main()
{
    int l,r;
    vector<reads>p;
    n=read();
    for (int i=1;i<=n;++i) a[i]=read(),s[i]=s[i-1]+a[i];
    m=read();
    for (int i=1;i<=m;++i) l=read(),r=read(),p.push_back((reads){l-1,r,i});
    solve(0,n,p);
    for (int i=1;i<=m;++i) printf("%lld %lld\n",ans[i].a/gcd(ans[i].a,ans[i].b),ans[i].b/gcd(ans[i].a,ans[i].b));
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 453ms
memory: 34668kb

input:

2000
-113 314 -664 697 211 -199 -38 -190 8 -661 910 -811 -113 942 77 433 -261 -368 129 -525 968 -608 -21 38 -562 438 -935 -228 220 333 985 -430 916 586 764 476 794 664 383 503 206 -60 380 -130 -988 -904 -996 -304 -286 31 114 119 850 -942 714 -369 -842 250 -192 -462 -727 -427 -602 126 231 718 121 559...

output:

54826875 11
405 -151
-2500 387
-144 223
1 -90
1 -8
-25 919
3249 -223
3249 -223
1 -8
-2 61
-321489 62
46225 -38
81 -85
1352 -425
-9 37
1 -90
49 -640
1 -827
-1369 354
89605156 31
8543929 4
4 -371
81 -1424
8 -109
8543929 4
35688676 11
0 1
7590025 -459
8 -109
0 1
128 -315
81 -1424
529 -129
64 -395
-4225...

result:

wrong answer 3rd numbers differ - expected: '14638276', found: '405'

Subtask #2:

score: 15
Accepted

Test #6:

score: 15
Accepted
time: 41ms
memory: 30816kb

input:

100000
754 792 -680 426 425 347 481 -690 530 378 73 -907 -431 45 -530 -552 440 -890 -15 712 695 -679 -310 13 718 805 193 -291 -877 -74 -355 511 -679 -395 166 -710 -657 -19 874 26 832 507 854 -289 700 -404 472 -302 -977 8 -698 40 766 705 369 838 700 -964 552 -535 -75 -608 -181 -503 468 447 772 904 -2...

output:

466344025 67

result:

ok 2 number(s): "466344025 67"

Test #7:

score: 0
Accepted
time: 28ms
memory: 38488kb

input:

100000
-387 -313 -47 -714 -74 239 8 591 541 -633 -660 981 -230 -148 -813 -802 -108 -543 -640 50 962 137 -972 -936 -975 885 793 -541 932 861 -348 885 -280 -977 -677 964 355 604 54 -977 -548 979 -516 136 437 -697 -23 -748 492 897 -538 785 617 -840 675 -978 307 -288 -493 682 678 -623 613 762 -622 -283 ...

output:

2417885584 385

result:

ok 2 number(s): "2417885584 385"

Test #8:

score: 0
Accepted
time: 30ms
memory: 30808kb

input:

100000
-127 303 92 -235 -794 293 -272 199 -175 693 -799 -750 -501 -283 -358 -657 -867 -152 -399 -299 530 -5 285 959 390 -928 617 -478 -889 -133 -492 -855 986 -664 -984 -690 887 -738 39 -570 -268 -767 640 883 711 -748 -75 426 -268 -541 -926 -792 902 214 561 -428 -285 781 -225 -299 -233 134 -896 569 -...

output:

202236841 30

result:

ok 2 number(s): "202236841 30"

Test #9:

score: 0
Accepted
time: 36ms
memory: 30868kb

input:

100000
-340 -696 48 -515 -584 -60 -888 257 214 -889 782 915 905 -964 -536 459 779 -519 -338 -867 622 -902 655 -153 600 -117 269 -887 -242 -985 -267 132 406 98 -368 400 -871 -908 -489 118 -140 -755 -869 -943 965 609 47 -748 194 -160 994 527 871 119 -891 580 -687 865 826 56 -978 -775 -47 792 313 -944 ...

output:

272184004 39

result:

ok 2 number(s): "272184004 39"

Test #10:

score: 0
Accepted
time: 28ms
memory: 30892kb

input:

100000
-736 -691 738 209 -411 -136 792 -110 -441 -753 254 744 -958 -317 312 856 245 995 912 87 -830 131 393 37 -400 934 279 -784 -308 618 -647 967 527 -162 -874 -770 188 -917 -855 772 482 -373 -749 -40 80 -459 710 -354 221 -343 -132 -947 -445 62 -744 851 848 554 -530 -892 -721 -910 -642 -138 -480 -7...

output:

393070276 51

result:

ok 2 number(s): "393070276 51"

Subtask #3:

score: 30
Accepted

Test #11:

score: 30
Accepted
time: 314ms
memory: 48728kb

input:

500000
794 -75 -596 -322 -945 -908 -609 -164 488 626 -877 -710 140 -120 -475 -837 738 669 634 -643 -682 667 816 -785 -608 -836 -860 -932 242 70 -620 268 -121 288 209 -392 732 750 558 -480 565 327 -217 -891 767 211 -690 -66 813 -889 952 615 432 19 411 800 678 718 522 422 940 -510 -544 449 -357 640 40...

output:

1878442281 242

result:

ok 2 number(s): "1878442281 242"

Test #12:

score: 0
Accepted
time: 359ms
memory: 48612kb

input:

500000
145 33 695 -456 761 -556 698 272 121 -445 100 -93 954 485 161 798 -279 921 456 570 151 -880 456 -640 -69 385 -301 -707 -84 -514 -964 597 874 346 841 274 -727 -177 -44 -883 903 -792 -776 926 416 -862 -247 -985 518 674 174 535 -295 960 -952 722 -947 -365 366 -520 -60 -404 800 811 -139 779 735 3...

output:

457831609 56

result:

ok 2 number(s): "457831609 56"

Test #13:

score: 0
Accepted
time: 342ms
memory: 48008kb

input:

500000
762 -391 336 983 -962 920 -428 955 487 -525 281 514 851 -508 607 153 -439 -307 345 557 -615 -997 272 813 -556 -69 -401 -625 143 -142 -499 380 749 613 -190 173 -633 -489 -285 183 -799 645 -863 379 169 -177 993 -184 753 346 58 770 254 705 -467 -700 -337 587 -333 685 -1 -618 -961 327 -33 -722 65...

output:

1160015481 110

result:

ok 2 number(s): "1160015481 110"

Test #14:

score: 0
Accepted
time: 319ms
memory: 47596kb

input:

500000
-819 -236 -303 662 -316 -328 51 821 717 -423 -565 -394 858 -816 -246 -993 831 -999 237 779 52 -642 826 945 307 -675 83 -715 -797 -451 -250 996 53 -765 -869 -717 -126 -250 532 -848 82 -100 542 80 798 701 -648 -433 234 362 462 -770 554 -211 -368 -653 897 -940 416 632 734 -18 727 319 -328 697 11...

output:

188897536 23

result:

ok 2 number(s): "188897536 23"

Test #15:

score: 0
Accepted
time: 544ms
memory: 48592kb

input:

500000
-161 619 -969 31 102 781 561 617 -685 -814 385 -998 911 -206 -404 519 276 -318 -731 -908 901 856 839 333 124 481 29 407 -315 -219 896 956 -286 996 -991 -800 951 109 -846 624 750 -88 955 -752 -814 134 -316 -777 844 391 359 -324 789 -713 -620 849 -553 575 357 792 -735 -828 373 378 -213 -501 -29...

output:

167832025 17

result:

ok 2 number(s): "167832025 17"

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 662ms
memory: 41176kb

input:

100000
-496 -233 354 -632 -196 177 -878 -255 -19 -636 685 -70 101 -975 -406 -988 -965 -205 563 -766 763 511 -116 -746 -129 14 106 928 -457 -257 -283 226 3 899 -359 -792 615 490 -57 986 -243 624 -239 931 -555 -821 -72 -611 -380 -397 248 -132 956 -195 -322 -231 319 -214 837 -379 -931 -301 -4 -673 280 ...

output:

1352474176 205
0 1
0 1
1 -28874
0 1
1 -3540
1 -35093
1 -18553
1 -14070
-128 8359
0 1
-16 27549
0 1
0 1
5 -4099
102171664 -11327
0 1
0 1
0 1
-28 13
-5 1393
1 -6395
1 -2257
64 -11037
25 -27002
1 -1938
0 1
676 -68059
0 1
289 -9403
1352474176 205
1 -5963
1 -35629
11 -3472
841 -704
-9 80017
8 -7493
0 1
0...

result:

wrong answer 3rd numbers differ - expected: '13957947', found: '0'

Subtask #5:

score: 0
Time Limit Exceeded

Test #31:

score: 0
Time Limit Exceeded

input:

100000
139 -485 -497 -818 254 169 -560 22 377 -67 -243 -75 743 -788 -676 -26 -775 371 576 -303 54 733 422 800 445 687 479 -16 -288 259 783 -586 912 616 439 -416 676 -555 172 659 501 -868 337 22 -60 260 603 -982 -149 466 769 -595 -117 949 -544 904 753 20 776 175 -888 937 -792 -647 -615 59 -298 452 -6...

output:


result: