QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#878332#9971. 新本格魔法少女りすかzlt0 11434ms21552kbC++144.9kb2025-02-01 14:49:292025-02-01 14:49:29

Judging History

This is the latest submission verdict.

  • [2025-02-01 14:49:29]
  • Judged
  • Verdict: 0
  • Time: 11434ms
  • Memory: 21552kb
  • [2025-02-01 14:49:29]
  • Submitted

answer

// Problem: P11365 [Ynoi2024] 新本格魔法少女りすか
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P11365
// Memory Limit: 128 MB
// Time Limit: 15000 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<int, int> 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 = 500100;
const int B = 400;

int n, m, a[maxn], bel[maxn], L[maxn], R[maxn], b[maxn], c[maxn];
ll ans[maxn];

struct List {
	int hd[maxn], len, nxt[maxn];
	pii val[maxn];
	
	inline void add(int x, pii y) {
		val[++len] = y;
		nxt[len] = hd[x];
		hd[x] = len;
	}
} T;

namespace BIT {
	int c[maxn];
	ull b[maxn];
	
	inline void update(int x, int d) {
		b[x >> 6] |= (1ULL << (x & 63));
		for (int i = (x >> 6) + 1; i <= (n >> 6) + 1; i += (i & (-i))) {
			c[i] += d;
		}
	}
	
	inline int query(int x) {
		int res = __builtin_popcountll(b[x >> 6] << (63 - (x & 63)));
		for (int i = (x >> 6); i; i -= (i & (-i))) {
			res += c[i];
		}
		return res;
	}
	
	inline void clear(int x) {
		b[x >> 6] = 0;
		for (int i = (x >> 6) + 1; i <= (n >> 6) + 1; i += (i & (-i))) {
			c[i] = 0;
		}
	}
}

void solve() {
	n = read();
	m = read();
	for (int i = 1; i <= n; ++i) {
		a[i] = read();
		bel[i] = (i - 1) / B + 1;
		if (!L[bel[i]]) {
			L[bel[i]] = i;
		}
		R[bel[i]] = i;
	}
	for (int i = 1, k, l, r; i <= m; ++i) {
		k = read();
		while (k--) {
			l = read();
			r = read();
			T.add(i, pii(l, r));
			if (bel[l] == bel[r]) {
				for (int j = l; j <= r; ++j) {
					ans[i] += BIT::query(a[j]);
				}
				for (int j = l; j <= r; ++j) {
					BIT::update(a[j], 1);
				}
			} else {
				for (int j = l; j <= R[bel[l]]; ++j) {
					ans[i] += BIT::query(a[j]);
				}
				for (int j = L[bel[r]]; j <= r; ++j) {
					ans[i] += BIT::query(a[j]);
				}
				for (int j = l; j <= R[bel[l]]; ++j) {
					BIT::update(a[j], 1);
				}
				for (int j = L[bel[r]]; j <= r; ++j) {
					BIT::update(a[j], 1);
				}
			}
		}
		for (int _ = T.hd[i]; _; _ = T.nxt[_]) {
			pii p = T.val[_];
			int l = p.fst, r = p.scd;
			if (bel[l] == bel[r]) {
				for (int j = l; j <= r; ++j) {
					BIT::clear(a[j]);
				}
			} else {
				for (int j = l; j <= R[bel[l]]; ++j) {
					BIT::clear(a[j]);
				}
				for (int j = L[bel[r]]; j <= r; ++j) {
					BIT::clear(a[j]);
				}
			}
		}
	}
	for (int k = 1; k <= bel[n]; ++k) {
		mems(b, 0);
		for (int i = L[k]; i <= R[k]; ++i) {
			++b[a[i]];
		}
		for (int i = 1; i <= n; ++i) {
			b[i] += b[i - 1];
		}
		for (int i = 1; i <= n; ++i) {
			if (i < L[k]) {
				c[i] = c[i - 1] + R[k] - L[k] + 1 - b[a[i]];
			} else if (i <= R[k]) {
				c[i] = c[i - 1];
			} else {
				c[i] = c[i - 1] + b[a[i] - 1];
			}
		}
		for (int i = 1; i <= m; ++i) {
			bool fl = 0;
			ll s = 0;
			for (int _ = T.hd[i]; _; _ = T.nxt[_]) {
				pii p = T.val[_];
				int l = p.fst, r = p.scd;
				int bl = bel[l] + 1, br = bel[r] - 1;
				if (bl <= k && k <= br) {
					fl = 1;
				} else if (r < L[k]) {
					s += c[r] - c[l - 1];
				} else if (l > R[k]) {
					if (!fl) {
						break;
					}
					if (bel[l] == bel[r]) {
						s += c[r] - c[l - 1];
					} else {
						s += c[R[bel[l]]] - c[l - 1] + c[r] - c[L[bel[r]] - 1];
					}
				}
			}
			if (fl) {
				ans[i] += s;
			}
		}
	}
	for (int i = 1; i <= m; ++i) {
		writeln(ans[i]);
	}
}

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

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 11434ms
memory: 21552kb

input:

500000 50174
453952 363686 491616 32825 57465 422945 471561 73291 421205 416554 23295 133266 242225 330448 25039 340064 28713 465664 162059 323880 28978 273728 101338 161413 294941 214275 63951 267981 294251 202822 253124 272510 3268 37918 139343 385983 111577 311901 487665 482827 347449 416029 3065...

output:

7924505153
1096035274
4015859334
7551629397
19715848016
5038947960
9413786128
5964260917
4600381085
3712265198
4373637732
8690986152
12434420249
10280536460
5103313944
2386284672
4607047530
14812276279
10912515919
17009258388
13716746960
4263300536
13134744588
9184386801
8874470932
6344822016
159669...

result:

wrong answer 1st numbers differ - expected: '37140482224', found: '7924505153'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 10
Accepted
time: 1477ms
memory: 20524kb

input:

500000 5
157360 289139 98034 293691 150262 268366 36782 147093 365410 444658 343224 375392 278298 357620 389673 167019 7747 119244 102126 83512 3649 459230 197365 245259 38071 249539 34617 213697 292553 389625 395778 280152 280038 239519 301475 232272 145919 370004 422791 271143 488283 185166 351026...

output:

50666226791
50440151159
50719090228
50631079493
50747050985

result:

ok 5 number(s): "50666226791 50440151159 50719090228 50631079493 50747050985"

Test #7:

score: 0
Wrong Answer
time: 1426ms
memory: 20528kb

input:

500000 5
70752 248917 41910 13653 177839 45858 54229 174152 10090 332231 437916 391622 432270 53875 446421 91921 461870 243336 363086 249844 338371 495447 423857 350363 365324 255747 170681 435791 177298 199582 240768 449011 302158 378518 233809 267343 362784 187864 114604 322031 255693 54447 406202...

output:

31286444026
5442266495
32353873575
4622328925
62373267184

result:

wrong answer 1st numbers differ - expected: '48041849427', found: '31286444026'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%