QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#623910 | #9429. Subarray | Zxyoul | AC ✓ | 734ms | 95112kb | C++20 | 3.9kb | 2024-10-09 14:21:19 | 2024-10-09 14:21:27 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define Cr(F, n) memset(F, 0, sizeof(int) * (n))
using namespace std;
const int mod = 998244353;
const int N = 4e5 + 10;
int limit, p, rev[N << 3];
int C[N << 3], D[N << 3];
inline void init(const int &n) {
for(limit = 1, p = 0; limit <= n; limit <<= 1, ++p);
for(int i = 0; i < limit; i++) {
rev[i] = (rev[i >> 1] >> 1 | (i & 1) << (p - 1));
}
}
inline int ADD(const int &x, const int &y) { return x + y >= mod ? x + y - mod : x + y; }
inline int SUB(const int &x, const int &y) { return x - y < 0 ? x - y + mod : x - y; }
inline int NY(int x, int p = mod - 2, int mul = 1) {
for(; p; p >>= 1, x = 1LL * x * x % mod)
if(p & 1) mul = 1LL * mul * x % mod;
return mul;
}
inline void NTT(int *f, const int &type, int limit = limit) {
int i, j, k;
for(i = 0; i < limit; i++) {
if(i < rev[i]) {
swap(f[i], f[rev[i]]);
}
}
for(i = 1; i < limit; i <<= 1) {
int m = i << 1, D = NY(3, type == 1 ? (mod - 1) / m : mod - 1 - (mod - 1) / m);
for(j = 0; j < limit; j += m) {
int W = 1;
for(k = 0; k < i; k++, W = 1LL * W * D % mod) {
int x = f[j + k], y = 1LL * f[i + j + k] * W % mod;
f[j + k] = ADD(x, y), f[i + j + k] = SUB(x, y);
}
}
}
if(type == -1) {
int Inv = NY(limit);
for(i = 0; i < limit; i++) {
f[i] = 1LL * f[i] * Inv % mod;
}
}
}
const int lg = 20;
int n;
int a[N], ans[N], b[N];
map<int, int> M;
vector< int > pos[N];
struct RMQ {
int st[lg][N];
void init() {
for(int i = 1; i <= n; i++) {
st[0][i] = a[i];
}
for(int i = 1; i < lg; i++) {
for(int j = 1; j <= n - (1 << i) + 1; j++) {
st[i][j] = max(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
}
}
}
int query(int l, int r) {
int k = __lg(r - l + 1);
return max(st[k][l], st[k][r - (1 << k) + 1]);
}
} R;
void Fz(int l, int r) {
if(l == r) {
ans[1]++;
return;
}
int id = M[R.query(l, r)];
int base = lower_bound(pos[id].begin(), pos[id].end(), l) - pos[id].begin();
vector< int > c;
int pre = l - 1;
for(int i = base; i < pos[id].size(); i++) {
if(pos[id][i] > r) break;
int cur = pos[id][i];
if(cur - pre != 1) {
Fz(pre + 1, cur - 1);
}
c.push_back(cur - pre);
pre = cur;
}
if(r != pre) {
Fz(pre + 1, r);
}
c.push_back(r - pre + 1);
int siz = c.size();
init(siz * 2 + 5);
Cr(C, limit); Cr(D, limit);
for(int i = 0; i < siz; i++) {
C[i] = c[i];
}
int cpr = 0;
for(int i = siz - 1; i >= 0; i--) {
D[i] = c[cpr++];
}
NTT(C, 1); NTT(D, 1);
for(int i = 0; i < limit; i++) {
C[i] = 1LL * C[i] * D[i] % mod;
}
NTT(C, -1);
int mx = siz - 1, posss = 0;
for(int i = 1; i <= siz - 1; i++) {
(ans[mx--] += C[posss++]) %= mod;
}
}
void solve() {
cin >> n;
for(int i = 1; i <= n; i++) { ans[i] = 0; }
for(int i = 1; i <= n; i++) {
cin >> a[i]; b[i] = a[i];
}
R.init();
sort(b + 1, b + 1 + n);
int pre = 0;
int cnt = 0;
for(int i = 1; i <= n; i++) {
if(b[i] != pre) {
M[b[i]] = ++cnt;
pre = b[i];
}
}
for(int i = 1; i <= n; i++) {
pos[M[a[i]]].push_back(i);
}
Fz(1, n);
int Ans = 0;
for(int i = 1; i <= n; i++) {
(Ans += 1LL * ans[i] * ans[i] % mod * i % mod) %= mod;
}
cout << Ans << '\n';
for(int i = 1; i <= cnt; i++) {
pos[i].clear();
}
M.clear();
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t = 1;
cin >> t;
while(t--) solve();
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 18028kb
input:
3 11 1 1 2 1 2 2 3 3 2 3 1 3 2024 5 26 3 1000000000 1000000000 1000000000
output:
2564 36 20
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 335ms
memory: 40728kb
input:
2522 12 642802746 634074578 642802746 634074578 642802746 634074578 634074578 642802746 740396295 634074578 740396295 634074578 16 305950462 400920468 400920468 305950462 400920468 305950462 400920468 400920468 400920468 400920468 305950462 305950462 400920468 305950462 305950462 305950462 2 4405082...
output:
3610 7545 9 1 50 1006 16170 5972 3117 540 540 4417 12885 336 3185 83 9272 27 1794 2776 1793 196 27 1377 8783 19723 5385 1864 3478 7101 1 431 825 4534 9900 162 21644 6 36 14088 306 9 57 1719 72 9 4637 68 16583 17701 19390 16282 5440 1 6 1716 19541 3823 2033 24 825 429 1911 11787 11388 12255 12175 126...
result:
ok 2522 lines
Test #3:
score: 0
Accepted
time: 484ms
memory: 44224kb
input:
1 400000 860350786 641009859 939887597 54748096 641009859 860350786 710156469 985188306 476927808 641009859 985188306 322595515 322595515 973764525 54748096 939887597 54748096 476927808 588586447 669240390 54748096 476927808 669240390 804928248 669240390 75475634 804928248 669240390 985188306 754756...
output:
300998364
result:
ok single line: '300998364'
Test #4:
score: 0
Accepted
time: 624ms
memory: 46584kb
input:
1 400000 860422965 880311831 389867323 711027909 603801945 977217669 127611088 468302420 100563882 896362064 321065270 937796491 106388135 679974087 799365054 508500258 155801089 72992050 568198964 469117950 605828088 147285088 931759705 335154243 123769214 717250374 123769214 588271814 193910044 58...
output:
642490751
result:
ok single line: '642490751'
Test #5:
score: 0
Accepted
time: 734ms
memory: 45916kb
input:
1 400000 489576972 624268112 792793292 261080167 299965397 570683924 43370033 865049228 160224484 597021302 799302320 154578623 616009875 817736437 422498140 177450324 576706528 701882608 322199948 469659816 265384591 886524303 331787804 922381773 642896492 36870304 922875786 328785523 506357505 778...
output:
728396411
result:
ok single line: '728396411'
Test #6:
score: 0
Accepted
time: 136ms
memory: 43852kb
input:
1 400000 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 79866982 798...
output:
805404149
result:
ok single line: '805404149'
Test #7:
score: 0
Accepted
time: 129ms
memory: 44288kb
input:
1 400000 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 4163012 416...
output:
871688808
result:
ok single line: '871688808'
Test #8:
score: 0
Accepted
time: 173ms
memory: 45728kb
input:
1 400000 7913 7913 7913 7913 7913 7913 7913 7913 7913 7913 7913 7913 7913 7913 7913 7913 7913 7913 7913 7913 7913 19512 844861162 178869991 19512 19512 19512 19512 19512 19512 19512 135989768 19512 19512 19512 19512 19512 19512 19512 19512 220217 220217 220217 220217 220217 220217 220217 220217 2202...
output:
470566238
result:
ok single line: '470566238'
Test #9:
score: 0
Accepted
time: 225ms
memory: 50072kb
input:
1 400000 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 1 2 1 2 1 1 2 1 2 2 1 2 1 2 2 1 1 1 1 2 1 1 1 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 1 2 2 1 2 2 2 1 1 2 2 1 2 2 1 1 1 1 2 2 1 1 1 1 2 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 2 2 2 2 1 2 1 2 1 1 2 2 2 1 1 1 2 1 1 1 1 2 2 2 1 1 2 2 1 2 2 1 1 1 2 1 2 2 2 1 1 2 1 2 1 1 2 2 2...
output:
188247686
result:
ok single line: '188247686'
Test #10:
score: 0
Accepted
time: 225ms
memory: 49992kb
input:
1 400000 1 1 1 1 1 2 2 1 1 1 2 2 1 2 2 1 2 1 1 2 1 1 2 1 2 2 1 2 2 1 2 2 2 1 2 1 2 2 2 1 1 1 2 2 1 2 2 1 1 1 2 1 2 1 2 2 1 2 1 2 1 1 1 2 2 1 1 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 1 2 1 1 2 1 2 1 2 1 1 1 1 2 1 1 2 2 1 1 1 2 2 1 2 1 1 1 2 1 1 2 1 1 1 1 1 2 1 1 1 2 2 1 2 2 1 1 1 2 1 1 1 1 2 1 1 1 2 1 2 1 2 2...
output:
534522621
result:
ok single line: '534522621'
Test #11:
score: 0
Accepted
time: 225ms
memory: 51264kb
input:
1 400000 2 2 1 1 1 2 1 1 2 2 1 1 1 1 1 1 1 1 2 1 2 2 1 2 2 2 2 1 1 2 1 2 1 1 2 2 2 2 1 2 1 2 1 1 1 2 2 1 2 1 1 1 2 1 1 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 1 1 1 2 2 1 2 2 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 2 1 2 1 2 2 1 2 2 1 1 2 1 2 1 1 2 1 1 2 1 2 1 2 2 2 1 2 2 1 1 2 1 2 2 2 1 2 1 1 2 1...
output:
315282614
result:
ok single line: '315282614'
Test #12:
score: 0
Accepted
time: 202ms
memory: 57156kb
input:
1 400000 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7...
output:
95707550
result:
ok single line: '95707550'
Test #13:
score: 0
Accepted
time: 205ms
memory: 44380kb
input:
1 400000 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 34618927 346...
output:
9261320
result:
ok single line: '9261320'
Test #14:
score: 0
Accepted
time: 119ms
memory: 44564kb
input:
1 400000 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 356559 3565...
output:
639541126
result:
ok single line: '639541126'
Test #15:
score: 0
Accepted
time: 152ms
memory: 47412kb
input:
1 400000 17752 17752 17752 17752 17752 17752 17752 17752 17752 17752 17752 17752 17752 17752 17752 17752 17752 17752 17752 17752 17752 17752 17752 130863 130863 130863 130863 130863 130863 130863 130863 130863 130863 130863 130863 130863 130863 130863 130863 130863 130863 130863 141618 141618 141618...
output:
910375995
result:
ok single line: '910375995'
Test #16:
score: 0
Accepted
time: 646ms
memory: 95112kb
input:
1 400000 2331 2331 18924 21959 27236 27236 30230 36415 36415 46142 53346 53346 61467 63373 63373 74413 75997 77628 79685 79685 85664 85664 85664 85837 87221 89355 89355 101697 101697 104022 104022 107252 107424 109721 116001 116001 116001 116888 117008 119514 121717 123822 123822 123822 128935 13039...
output:
830312990
result:
ok single line: '830312990'
Test #17:
score: 0
Accepted
time: 226ms
memory: 57048kb
input:
1 400000 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777...
output:
951683280
result:
ok single line: '951683280'
Test #18:
score: 0
Accepted
time: 209ms
memory: 59320kb
input:
1 400000 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777...
output:
146950933
result:
ok single line: '146950933'
Test #19:
score: 0
Accepted
time: 213ms
memory: 59136kb
input:
1 400000 777 777 777 228 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 167 777 777 777 777 777 777 777 133 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777...
output:
351398572
result:
ok single line: '351398572'
Extra Test:
score: 0
Extra Test Passed