QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#184626 | #4322. rsraogps / 雪に咲く花 | Lynkcat | AC ✓ | 610ms | 230976kb | C++17 | 2.5kb | 2023-09-20 23:57:14 | 2023-09-20 23:57:14 |
Judging History
answer
#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < unsigned int,unsigned int >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
#define N 1000005
using namespace std;
char obuf[1 << 27], *o(obuf);
inline char gc(){static char buf[1<<23],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?EOF:*p1++;}
// #define gc getchar
inline ll read(){char c=gc();ll su=0,f=1;for (;c<'0'||c>'9';c=gc()) if (c=='-') f=-1;for (;c>='0'&&c<='9';c=gc()) su=su*10+c-'0';return su*f;}
inline void write(ll x){if (x<0){putchar('-');write(-x);return;}if (x>=10) write(x/10);putchar(x%10+'0');}
inline void writesp(ll x){write(x),putchar(' ');}
inline void writeln(ll x){write(x);putchar('\n');}
void print(uint x) {
if (x > 9)
print(x / 10);
*o++ = x % 10 + '0';
}
unsigned int n,m,a[N],b[N],c[N],ans[N*5];
unsigned int prea[N],preb[N],sum[N],sb[N];
pair<pa,int> all[N*5],all1[N*5];
inline int gcd(int x,int y)
{
return (y==0)?x:gcd(y,x%y);
}
void BellaKira()
{
n=read(),m=read();
for (int i=1;i<=n;i++) a[i]=read();
for (int i=1;i<=n;i++) b[i]=read();
for (int i=1;i<=n;i++) c[i]=read();
// m=2;
for (int i=1;i<=m;i++)
{
int l=read(),r=read();
sum[r]++;
all[i]=mp(mp(r,l),i);
all1[i]=all[i];
}
for (int i=1;i<=n;i++)
sum[i]+=sum[i-1];
for (int i=1;i<=m;i++)
all[sum[all1[i].fi.fi]--]=all1[i];
poly g;
for (int i=1,pos=1;i<=n;i++)
{
int t=i;
for (int j=i-1;j>=1;j--)
{
int x=a[j]&a[i];
if (x==a[j]) break;
if (j<t) sb[j]+=(prea[j]-prea[j-1])*(i-1),t=j;
a[j]=x;
}
for (int j=i-1;j>=1;j--)
{
int x=b[j]|b[i];
if (x==b[j]) break;
if (j<t) sb[j]+=(prea[j]-prea[j-1])*(i-1),t=j;
b[j]=x;
}
int lst=-1;
for (int j=i-1;j>=1;j--)
{
if (lst!=c[j]&&c[i]%c[j]==0) break;
lst=c[j];
if (j<t) sb[j]+=(prea[j]-prea[j-1])*(i-1),t=j;
c[j]=gcd(c[j],c[i]);
}
for (int j=t;j<=i;j++)
{
int v=a[j]*b[j]*c[j];
sb[j]+=-v*(i-1);
prea[j]=prea[j-1]+v,
preb[j]=preb[j-1]+sb[j];
}
while (pos<=m&&all[pos].fi.fi==i)
{
int l=all[pos].fi.se,id=all[pos].se;
{
int A=prea[i]-prea[l-1];
int B=preb[i]-preb[l-1];
ans[id]+=A*i+B;
}
pos++;
}
}
for (int i=1;i<=m;i++) print(ans[i]),
*o++ = '\n';
fwrite(obuf, o - obuf, 1, stdout);
}
signed main()
{
int T=1;
while (T--)
{
BellaKira();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 521ms
memory: 230972kb
input:
1000000 4999998 677759 16844 194149 882507 258413 301124 335220 853562 556891 940146 265534 89372 852421 821748 453468 389493 767295 749954 967376 543995 891396 399529 837606 300380 188426 701042 209657 534843 857430 548210 681875 715389 276811 492296 717786 463046 233941 281371 641808 990695 702677...
output:
3578099829 247368737 4134953488 123772255 4271316421 2664004035 1981625521 4161064085 2301764273 3633218207 446408196 4089220553 2146535877 2604957438 3629218607 861849275 2324734025 926506509 652453278 2182055877 4151704810 1597517111 4271912484 2355275472 3461746888 548698842 2016320224 3911771642...
result:
ok 4999998 lines
Test #2:
score: 0
Accepted
time: 595ms
memory: 230960kb
input:
999998 4999996 148476 933817 864076 191969 417231 462700 788827 950163 335378 379496 488829 873292 674723 936352 247899 950658 425452 840996 362963 260838 362545 281279 425178 922053 555678 230269 421254 27589 706638 989848 143104 701781 516547 911894 563207 927853 991791 523934 307480 220695 177834...
output:
4047299131 1051838109 3042044620 1558935111 1922407201 1863823247 2914705420 2124780582 4203879976 1785092444 2759734979 4070466544 1369322115 1659410325 4213137446 1668610392 1639252119 1374451942 2112308793 2665853985 2065466007 1116739408 1109187438 2946166785 1779189545 243189148 3803243245 2351...
result:
ok 4999996 lines
Test #3:
score: 0
Accepted
time: 610ms
memory: 230976kb
input:
1000000 4999995 931616 451627 120237 821848 952685 820911 815844 532508 577534 854247 662620 828334 73938 275051 693099 935029 7291 912115 629721 109400 854959 821474 633595 172529 811334 202115 216622 710254 430042 382387 231224 945397 487320 601716 141624 713279 35449 454713 718139 667184 647847 1...
output:
1854807511 1453890769 829715466 2750235612 2667615988 2011865121 3886268553 81652698 2457883979 3659326530 3810577703 1430781613 2476318782 355131279 1910386131 1675955906 73042715 2580008178 3970786863 1183731076 431877656 1623138021 4112331510 1909031133 2098507060 1572114178 943542298 2024138600 ...
result:
ok 4999995 lines
Test #4:
score: 0
Accepted
time: 545ms
memory: 228160kb
input:
1000000 5000000 75897 317375 987088 796858 836675 641647 263292 762783 906917 788998 428151 438194 253036 218108 762369 399386 891960 713342 843235 551031 867029 570219 385429 885157 701201 409353 378913 109046 178496 109405 731382 519077 349818 745266 996624 221075 803954 354627 221988 844157 86282...
output:
2966942011 654898707 1927440301 3400761133 2177168211 1995882779 13177838 549258702 1875962477 1553623849 4097174058 3593016054 2807042864 1511868884 1638704141 1825858112 4225259969 2573853400 1025189954 276399961 4092039218 1669310089 1694510238 3170716855 4083645546 3691686413 390517363 101103702...
result:
ok 5000000 lines
Test #5:
score: 0
Accepted
time: 597ms
memory: 228812kb
input:
1000000 4999997 550694 365463 501771 524682 78663 490932 110963 596306 170635 15804 841054 140182 542832 359374 149767 117371 781644 589807 766539 819208 623548 221522 311259 369349 172084 757907 266396 216423 872615 103742 10177 77854 70225 72875 239011 751514 842561 499348 934175 510072 69511 5677...
output:
36193191 886256281 67036801 1717600085 3843055089 1231176396 1949909599 4115235600 1721613847 598865947 3238563141 2978801667 3849836475 4229008672 1696414796 1319545749 376680960 2776757522 4014555166 3828164404 3117898481 284258382 4234109452 873912775 3158947710 924528144 735582366 1442011906 382...
result:
ok 4999997 lines
Test #6:
score: 0
Accepted
time: 495ms
memory: 228216kb
input:
1000000 5000000 158505 484242 818677 38611 836396 12906 853956 426999 313936 280906 221632 594322 744811 438772 316870 856331 493875 386340 634576 874457 793288 808642 448941 622183 505885 659057 884202 365701 185506 605172 622993 473312 642735 74475 930723 83076 654730 765135 503821 315952 55660 13...
output:
4163463972 1941994169 2249001160 2405453139 2053533005 3139826285 4031121556 1186297491 633421476 1232239287 2333477925 2281357749 398332473 1922007652 2509481069 585346094 1422591305 4203830315 3402079463 592707399 2029318113 3974367781 1563822415 704095071 2118299394 557630578 325255108 2435978031...
result:
ok 5000000 lines
Test #7:
score: 0
Accepted
time: 573ms
memory: 228924kb
input:
999997 5000000 98288 733168 657995 501252 341673 872074 782002 550934 135535 595883 666434 435845 40585 113385 828212 139698 846289 516232 677009 411045 461125 78604 140037 997530 936999 297687 677813 821128 312037 609783 809348 671168 841648 266158 267116 400314 31450 976894 8523 885488 115191 2302...
output:
481643023 957353848 2386801765 2701247801 2431828966 1387327118 2977774348 586822418 878575845 2469938972 3165210311 4288129909 3884116150 2310630919 3588902110 3173529303 1165423824 1057156386 230165554 543694124 3096266748 959479279 3106946175 65449923 476336922 1538803634 1537225184 2959099509 20...
result:
ok 5000000 lines
Test #8:
score: 0
Accepted
time: 548ms
memory: 229680kb
input:
999997 4999998 880961 509539 223060 542684 863171 314039 257098 858313 399694 245225 638370 632033 466243 183421 880483 986946 541583 671470 290842 894744 983052 126767 433952 249673 876439 862922 209323 360659 187825 441663 373866 118204 665382 997819 698409 645602 27055 988282 801169 685583 754750...
output:
1950434979 2535368862 1295181054 2440636499 324430097 2836171671 3398683412 494426224 2534895612 55770942 2349891156 1745289686 3859448784 3378460685 3713435827 619917835 2050514425 1378277866 658642646 1481801691 908541645 1897519343 4257177381 1869245020 2814465779 822075044 2710626849 4121678663 ...
result:
ok 4999998 lines
Test #9:
score: 0
Accepted
time: 566ms
memory: 228768kb
input:
999996 4999996 710324 608547 629032 956830 420404 580528 182245 196692 656230 840084 893692 603070 595230 9441 170160 885273 848998 559173 606387 396359 549755 270885 787619 436056 295544 606492 628511 513967 954941 639515 651373 651101 269437 220216 704907 2499 214226 736336 767717 563698 256240 52...
output:
642434687 1873983384 2041785282 52874134 369481520 1651294012 3459359105 2673953664 2817559202 2945438418 4145828776 3988213358 2627328114 450253467 3113166251 3676890680 3254753957 3041830028 1939936716 4129931161 2925947627 3257591656 2472883312 2769869814 4051954006 2511891595 4018793716 35157085...
result:
ok 4999996 lines
Test #10:
score: 0
Accepted
time: 583ms
memory: 228976kb
input:
1000000 4999998 849733 751642 204965 44814 725839 308863 631838 983711 422166 349805 141 661471 623393 515635 561659 360667 681652 403870 294162 339449 911657 988703 470874 817281 805409 121085 454062 703174 256521 12301 237390 197824 808220 585838 911206 849330 709774 737442 570660 367171 498069 90...
output:
310144113 3595095217 750890549 1328393156 1966438225 348818360 774108967 336691654 1730794304 830975029 1107364901 3871918090 2798314495 2113280853 885432872 2595425447 2385500607 3260812024 4197908666 2308497201 2335013545 2130139499 818098835 1660494080 3437232658 4212036597 59181712 3176291658 56...
result:
ok 4999998 lines