QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#878317 | #9971. 新本格魔法少女りすか | zlt | 10 | 14895ms | 36396kb | C++14 | 4.7kb | 2025-02-01 14:46:08 | 2025-02-01 14:46:08 |
Judging History
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];
vector<pii> qq[maxn];
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();
qq[i].pb(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 (pii p : qq[i]) {
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 (pii p : qq[i]) {
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
Time Limit Exceeded
Test #1:
score: 10
Accepted
time: 14895ms
memory: 36264kb
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:
37140482224 34639976441 43969281986 34161334900 43989474268 29265925652 42055490065 29273522769 34470649558 31057021177 45082279891 42633045968 24965661308 47949427314 39934839547 31946722251 32202412878 31922452884 44736436824 46173193393 35015845935 31452020651 33994126195 30526716598 43413051959 ...
result:
ok 50174 numbers
Test #2:
score: 10
Accepted
time: 14893ms
memory: 36396kb
input:
500000 50000 483761 409384 371372 391186 181478 207855 91628 218748 274582 265418 253052 76826 15670 437134 6073 481510 474741 265520 496126 419159 129713 345118 468460 25917 365284 188440 218808 392357 8582 430707 365623 153604 139041 106196 150460 130300 252376 489428 395824 241387 368417 95440 33...
output:
33379126763 35734775083 46176544848 34597699495 37833169095 27623267186 41223330149 34969135626 32487873161 35347692293 35405163350 28110269917 25007599842 35432802577 32651348179 32686686317 26740651161 35614149923 47276786044 40221083758 46199666623 43754128347 28131948134 40539846117 22592070794 ...
result:
ok 50000 numbers
Test #3:
score: 0
Time Limit Exceeded
input:
500000 90715 49734 488827 125852 60078 137383 48439 427068 44266 117506 69998 16642 269329 353883 144088 292157 389881 97531 139928 333915 163713 404665 166720 281339 195742 418467 144699 274331 57762 268692 338157 220132 187518 298819 96797 306755 45962 406942 315596 356490 460108 463956 101319 382...
output:
result:
Subtask #2:
score: 10
Accepted
Test #6:
score: 10
Accepted
time: 2009ms
memory: 30312kb
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: 10
Accepted
time: 1868ms
memory: 32640kb
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:
48041849427 47573923544 48149375837 46484835228 62373267184
result:
ok 5 number(s): "48041849427 47573923544 48149375837 46484835228 62373267184"
Test #8:
score: 10
Accepted
time: 2026ms
memory: 32348kb
input:
500000 5 241608 419462 82981 424356 17797 426283 105137 396042 362939 472171 51823 373467 302031 234957 103628 345691 280071 391667 370350 226645 393628 99397 111403 124617 289298 487366 430929 445895 146724 165853 250446 134811 333218 232414 263197 300887 194261 147235 493474 305082 109715 82765 16...
output:
50381279295 50436234418 50754046820 50457636384 51060372228
result:
ok 5 number(s): "50381279295 50436234418 50754046820 50457636384 51060372228"
Test #9:
score: 10
Accepted
time: 1852ms
memory: 35016kb
input:
500000 5 384662 360905 151827 77657 463152 472106 142072 464841 224605 243338 468024 153983 367505 347441 107735 63958 144215 118222 294699 106900 236160 308499 164080 9056 373110 343094 108210 164120 416292 77276 327997 344605 375908 60401 331692 169348 431340 174229 301328 62849 130369 272892 1802...
output:
47987223119 47114724607 47699758559 47424207451 62476342231
result:
ok 5 number(s): "47987223119 47114724607 47699758559 47424207451 62476342231"
Test #10:
score: 10
Accepted
time: 2018ms
memory: 32424kb
input:
500000 5 454113 396339 270960 34848 390907 416021 317393 9900 333318 50842 198100 115 286821 210759 79669 257489 94065 308047 220510 343737 11392 410497 58962 488921 315855 115533 11194 298501 112352 81722 415920 175976 463840 491310 29020 479390 494454 375738 37344 278711 347144 351121 38809 194902...
output:
50554118536 50349176037 50371935305 50817175419 50798953918
result:
ok 5 number(s): "50554118536 50349176037 50371935305 50817175419 50798953918"
Subtask #3:
score: 0
Skipped
Dependency #1:
0%