QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#888073#7438. 樋口円香zltAC ✓1731ms23532kbC++144.7kb2025-02-07 21:54:082025-02-07 21:54:09

Judging History

This is the latest submission verdict.

  • [2025-02-07 21:54:09]
  • Judged
  • Verdict: AC
  • Time: 1731ms
  • Memory: 23532kb
  • [2025-02-07 21:54:08]
  • Submitted

answer

// Problem: P8527 [Ynoi2003] 樋口円香
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P8527
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

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

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

namespace IO {
	const int maxn = 1 << 20;
	
    char ibuf[maxn], *iS, *iT, obuf[maxn], *oS = obuf;

	inline char gc() {
		return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin), (iS == iT ? EOF : *iS++) : *iS++);
	}

	template<typename T = int>
	inline T read() {
		char c = gc();
		T x = 0;
		bool f = 0;
		while (c < '0' || c > '9') {
			f |= (c == '-');
			c = gc();
		}
		while (c >= '0' && c <= '9') {
			x = (x << 1) + (x << 3) + (c ^ 48);
			c = gc();
		}
		return f ? ~(x - 1) : x;
	}

	inline void flush() {
		fwrite(obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	
	struct Flusher {
		~Flusher() {
			flush();
		}
	} AutoFlush;

	inline void pc(char ch) {
		if (oS == obuf + maxn) {
			flush();
		}
		*oS++ = ch;
	}

	template<typename T>
	inline void write(T x) {
		static char stk[64], *tp = stk;
		if (x < 0) {
			x = ~(x - 1);
			pc('-');
		}
		do {
			*tp++ = x % 10;
			x /= 10;
		} while (x);
		while (tp != stk) {
			pc((*--tp) | 48);
		}
	}
	
	template<typename T>
	inline void writesp(T x) {
		write(x);
		pc(' ');
	}
	
	template<typename T>
	inline void writeln(T x) {
		write(x);
		pc('\n');
	}
}

using IO::read;
using IO::write;
using IO::pc;
using IO::writesp;
using IO::writeln;

const int maxn = 100100;
const int B = 1500;
const int maxm = 1000100;
const int mod = 1004535809, G = 3;

inline int qpow(int b, int p) {
	int res = 1;
	while (p) {
		if (p & 1) {
			res = 1LL * res * b % mod;
		}
		b = 1LL * b * b % mod;
		p >>= 1;
	}
	return res;
}

int n, m, a[maxn], b[maxn], r[maxm];
struct node {
	int l, r, k;
} c[maxm];

typedef vector<int> poly;

inline void NTT(vector<int> &a, int op) {
	int n = (int)a.size();
	for (int i = 0; i < n; ++i) {
		if (i < r[i]) {
			swap(a[i], a[r[i]]);
		}
	}
	for (int k = 1; k < n; k <<= 1) {
		int wn = qpow(op == 1 ? G : qpow(G, mod - 2), (mod - 1) / (k << 1));
		poly pw(k);
		pw[0] = 1;
		for (int i = 1; i < k; ++i) {
			pw[i] = 1LL * pw[i - 1] * wn % mod;
		}
		for (int i = 0; i < n; i += (k << 1)) {
			for (int j = 0; j < k; ++j) {
				int x = a[i + j], y = 1LL * a[i + j + k] * pw[j] % mod;
				a[i + j] = (x + y < mod ? x + y : x + y - mod);
				a[i + j + k] = (x < y ? x - y + mod : x - y);
			}
		}
	}
	if (op == -1) {
		int inv = qpow(n, mod - 2);
		for (int i = 0; i < n; ++i) {
			a[i] = 1LL * a[i] * inv % mod;
		}
	}
}

inline poly operator * (poly a, poly b) {
	NTT(a, 1);
	NTT(b, 1);
	int n = (int)a.size();
	for (int i = 0; i < n; ++i) {
		a[i] = 1LL * a[i] * b[i] % mod;
	}
	NTT(a, -1);
	return a;
}

inline poly mul(const poly &a, const poly &b) {
	int n = (int)a.size() - 1, m = (int)b.size() - 1, k = 0;
	while ((1 << k) <= n + m) {
		++k;
	}
	for (int i = 1; i < (1 << k); ++i) {
		r[i] = (r[i >> 1] >> 1) | ((i & 1) << (k - 1));
	}
	poly A(1 << k), B(1 << k);
	for (int i = 0; i <= n; ++i) {
		A[i] = a[i];
	}
	for (int i = 0; i <= m; ++i) {
		B[i] = b[i];
	}
	poly res = A * B;
	res.resize(n + m + 1);
	return res;
}

void solve() {
	n = read();
	for (int i = 1; i <= n; ++i) {
		a[i] = read();
	}
	m = read();
	for (int i = 1; i <= m; ++i) {
		c[i].l = read();
		c[i].r = read();
		c[i].k = read();
		int l = c[i].l, r = c[i].r, k = c[i].k;
		int bl = (l + B - 1) / B, br = (r + B - 1) / B;
		if (bl == br) {
			for (int i = l; i <= r; ++i) {
				b[k + i - l] += a[i];
			}
		} else {
			for (int i = l; i <= B * bl; ++i) {
				b[k + i - l] += a[i];
			}
			for (int i = B * (br - 1) + 1; i <= r; ++i) {
				b[k + i - l] += a[i];
			}
		}
		c[i].k -= c[i].l;
		c[i].l = bl;
		c[i].r = br;
	}
	for (int k = 1; k <= (n + B - 1) / B; ++k) {
		int l = (k - 1) * B + 1, r = min(k * B, n);
		poly A(r - l + 1), B(n - r + l);
		for (int i = l; i <= r; ++i) {
			A[i - l] = a[i];
		}
		for (int i = 1; i <= m; ++i) {
			if (c[i].l < k && k < c[i].r) {
				int p = c[i].k + l;
				++B[p - 1];
			}
		}
		poly C = mul(A, B);
		for (int i = 1; i <= n; ++i) {
			b[i] += C[i - 1];
		}
	}
	for (int i = 1; i <= n; ++i) {
		printf("%d\n", b[i]);
	}
}

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

详细

Test #1:

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

input:

1000
629 353 463 242 579 37 341 579 751 331 971 209 993 230 150 893 723 872 154 456 443 858 815 904 643 97 471 510 695 436 306 499 371 971 494 147 702 903 795 968 731 890 594 590 356 63 313 564 718 680 525 284 848 154 36 858 367 454 723 351 580 80 102 308 680 598 185 681 706 494 725 951 248 570 793 ...

output:

9812
18329
25519
40685
50358
58477
67055
71202
84917
83471
95554
98972
114054
112482
126642
125010
144914
147671
141407
162102
164317
170828
171245
193368
183842
180062
189229
195363
201525
208055
211890
218246
222774
237496
232051
230084
240108
247492
257506
259433
262038
254605
259817
258900
25715...

result:

ok 1000 lines

Test #2:

score: 0
Accepted
time: 840ms
memory: 12988kb

input:

100000
984 353 333 932 661 754 360 57 828 818 156 676 408 992 550 847 743 689 198 782 144 163 27 320 781 316 966 842 84 797 588 39 867 498 675 598 345 159 491 1000 46 874 992 829 838 575 542 836 541 30 393 998 762 434 978 382 34 862 446 828 283 820 537 293 597 240 198 258 404 929 977 588 138 214 504...

output:

11337
20492
27617
38150
59067
68173
78360
91299
95892
109338
125673
129644
134532
153938
162487
181716
190109
202080
211662
217170
233126
223881
247707
269064
262512
271414
292008
286305
310010
326696
327857
340549
356849
355034
385112
396461
394276
401687
431908
429402
436902
456239
480823
466472
4...

result:

ok 100000 lines

Test #3:

score: 0
Accepted
time: 1678ms
memory: 23532kb

input:

100000
770 158 194 936 605 941 814 119 685 202 611 549 697 350 322 412 751 477 433 316 489 211 428 467 47 155 318 646 342 664 801 700 466 584 494 455 350 801 315 65 323 248 952 506 429 320 798 591 272 702 475 708 457 911 421 957 642 737 75 483 938 415 371 945 792 88 400 928 125 850 140 313 121 4 784...

output:

371669
747329
1146914
1544890
1951278
2344214
2671548
3011240
3361942
3682875
4053079
4355837
4673991
4995561
5351185
5649899
5988989
6396368
6630334
6926213
7229448
7600320
7823165
8256958
8525065
8836172
9164533
9645612
9980857
10304819
10655807
10957867
11309644
11491081
11842439
12131144
1247762...

result:

ok 100000 lines

Test #4:

score: 0
Accepted
time: 1731ms
memory: 22260kb

input:

100000
353 321 823 423 572 507 218 465 497 519 453 452 684 21 764 867 981 119 152 830 536 866 685 8 579 68 965 889 531 709 207 766 160 771 412 231 480 238 284 517 17 432 383 379 762 272 612 589 196 46 911 165 710 748 2 18 943 270 484 316 935 518 496 886 747 989 398 604 722 383 537 818 591 347 149 32...

output:

10674
22292
36969
47709
49953
58490
62009
74704
86454
95951
102377
116026
122769
138788
145124
163696
177331
167829
188244
187890
217197
216718
229361
234397
253240
258627
267010
271325
286377
283180
301260
313803
332054
342858
346379
368019
377504
381487
408040
413169
416129
411884
417746
435234
45...

result:

ok 100000 lines