QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#187957#4322. rsraogps / 雪に咲く花zltAC ✓769ms111112kbC++143.1kb2023-09-25 09:22:322023-09-25 09:22:33

Judging History

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

  • [2023-09-25 09:22:33]
  • 评测
  • 测评结果:AC
  • 用时:769ms
  • 内存:111112kb
  • [2023-09-25 09:22:32]
  • 提交

answer

// Problem: P9335 [Ynoi2001] 雪に咲く花
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P9335
// Memory Limit: 512 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define scd second
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<int, int> pii;

namespace IO {
    char ibuf[(1 << 20) + 1], *iS, *iT, obuf[(1 << 20) + 1], *oS = obuf;
#define writesp(x) write(x), pc(' ')
#define writeln(x) write(x), pc('\n')
#define gh() (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), (iS == iT ? EOF : *iS++) : *iS++)
    inline uint read() {
        char ch = gh();
        uint x = 0;
        while (ch < '0' || ch > '9') ch = gh();
        while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gh();
        return x;
    }
    inline void flush () {
    	fwrite(obuf, 1, oS - obuf, stdout), oS = obuf;
	}
    inline void pc (char ch) {
    	if (oS == obuf + (1 << 20) + 1) flush(); 
    	*oS++ = ch;
	}
	template<typename _Tp>
    inline void write (_Tp x) {
    	static char stk[64], *tp = stk;
		do *tp++ = x % 10, x /= 10;
		while (x);
		while (tp != stk) pc((*--tp) | 48);
    }
}

using IO::read;
using IO::write;
using IO::pc;
using IO::flush;

const int maxn = 1000100;
const int maxm = 5000100;

int n, m, t, d[maxn], id[maxm], L[maxm], R[maxm];
uint ans[maxm], a[maxn], b[maxn], c[maxn], f[maxn], g[maxn], h[maxn];

void solve() {
    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();
    }
    for (int i = 1, l, r; i <= m; ++i) {
    	l = read();
    	r = read();
    	L[i] = l;
    	R[i] = r;
    	++d[r];
    }
    int s = 0;
    for (int i = 1; i <= n; ++i) {
    	s += d[i];
    	d[i] = s - d[i];
    }
    for (int i = 1; i <= m; ++i) {
    	id[++d[R[i]]] = i;
    }
    for (int i = 1, k = 1; i <= n; ++i) {
    	int j = i - 1;
    	while (j) {
    		uint x = a[j] & a[j + 1], y = b[j] | b[j + 1], z = __gcd(c[j], c[j + 1]);
    		if ((x ^ a[j]) || (y ^ b[j]) || (z ^ c[j])) {
    			a[j] = x;
    			b[j] = y;
    			c[j] = z;
    			--j;
    		} else {
    			break;
    		}
    	}
    	f[i] = f[i - 1] + g[i - 1] * (t - h[i - 1]);
    	uint x = g[j];
    	++j;
    	while (j <= i) {
    		f[j] += g[j] * (t - h[j]);
    		g[j] = (x += a[j] * b[j] * c[j]);
    		h[j] = t;
    		++j;
    	}
    	++t;
    	uint p = f[i] + g[i] * (t - h[i]);
    	while (k <= d[i]) {
    		int o = id[k];
    		int l = L[o];
    		ans[o] = p - (f[l - 1] + g[l - 1] * (t - h[l - 1]));
    		++k;
    	}
    }
    for (int i = 1; i <= m; ++i) {
    	writeln(ans[i]);
    }
    flush();
}

int main() {
    int T = 1;
    // scanf("%d", &T);
    while (T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 622ms
memory: 110964kb

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: 679ms
memory: 111108kb

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: 744ms
memory: 111108kb

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: 689ms
memory: 110940kb

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: 716ms
memory: 111108kb

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: 637ms
memory: 110944kb

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: 716ms
memory: 110936kb

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: 734ms
memory: 110824kb

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: 769ms
memory: 110932kb

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: 747ms
memory: 111112kb

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