QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#786311 | #8079. Range Periodicity Query | lfyszy | WA | 504ms | 104912kb | C++14 | 2.9kb | 2024-11-26 21:04:19 | 2024-11-26 21:04:27 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define SP << " " <<
#define fish signed
using namespace std;
mt19937 rnd(1209);
const int INF = 0x3f3f3f3f3f3f3f3f;
const int base = 66683, N = 5e5 + 10, base2 = 131, mod = 998244353;
unsigned long long prod[N], h[N];
long long prod2[N], h2[N];
int get(int l, int r) {return h[r] - h[l - 1] * prod[r - l + 1];}
int get2(int l, int r) {return ((h2[r] - h2[l - 1] * prod2[r - l + 1] % mod) % mod + mod) % mod;}
int sl[N], sr[N], t[N]; char a[N];
int mn[N << 2];
#define ls(u) (u << 1)
#define rs(u) (u << 1 | 1)
void modify(int u, int l, int r, int pos, int k)
{
chmin(mn[u], k);
if(l == r) return ;
int mid = l + r >> 1;
if(pos <= mid) modify(ls(u), l, mid, pos, k);
else modify(rs(u), mid + 1, r, pos, k);
}
int query(int u, int l, int r, int ql, int qr)
{
if(ql <= l && r <= qr) return mn[u];
int mid = l + r >> 1, res = INF;
if(ql <= mid) chmin(res, query(ls(u), l, mid, ql, qr));
if(qr > mid) chmin(res, query(rs(u), mid + 1, r, ql, qr));
return res;
}
struct node {int l, r, id;} ;
int ans[N];
vector<node> vp[N];
vector<node> vq[N];
fish main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int hh = n + 1, tt = n;
for(int i = 1; i <= n; i ++)
{
char ch; cin >> ch;
if('A' <= ch && ch <= 'Z') a[-- hh] = ch - 'A' + 'a';
else a[++ tt] = ch;
sl[i] = hh, sr[i] = tt;
}
prod[0] = prod2[0] = 1;
for(int i = 1; i <= n; i ++) prod[i] = prod[i - 1] * base;
for(int i = hh; i <= tt; i ++) h[i] = h[i - 1] * base + a[i];
for(int i = 1; i <= n; i ++) prod2[i] = (prod2[i - 1] * base2) % mod;
for(int i = hh; i <= tt; i ++) h2[i] = (h2[i - 1] * base2 % mod + a[i]) % mod;
for(int i = 1; i <= n; i ++)
{
int l = i, r = n, res = i;
while(l <= r)
{
int mid = l + r >> 1;
int l1 = sl[mid], l2 = sl[mid] + i;
int r1 = sr[mid] - i, r2 = sr[mid];
if(get(l1, r1) == get(l2, r2) && get2(l1, r1) == get2(l2, r2)) l = mid + 1, res = mid;
else r = mid - 1;
}
t[i] = res;
}
int m; cin >> m;
for(int i = 1; i <= m; i ++) {int x; cin >> x; vp[t[x]].push_back({i, x});}
memset(mn, 0x3f, sizeof mn);
int k; cin >> k;
for(int i = 1; i <= k; i ++) {int k, l, r; cin >> k >> l >> r; vq[k].push_back({l, r, i});}
for(int i = n; i >= 1; i --)
{
for(auto v : vp[i]) modify(1, 1, m, v.l, v.r);
for(auto v : vq[i]) {ans[v.id] = query(1, 1, m, v.l, v.r); if(ans[v.id] > i) ans[v.id] = -1;}
// for(int j = 1; j <= m; j ++) cerr << query(1, 1, m, j, j) << " "; cerr << "\n";
}
for(int i = 1; i <= k; i ++) cout << (ans[i] == INF ? -1 : ans[i]) << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 7ms
memory: 54980kb
input:
7 AABAAba 9 4 3 2 1 7 5 3 6 1 6 1 4 4 2 1 4 2 1 3 3 3 5 5 4 7 7 8 9
output:
1 1 2 -1 3 6
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 202ms
memory: 86588kb
input:
200000 BAbBbBabBBbbABbbaBbaaabaBBAbBbBAAAAABBaBaAAabBAAbABaaBABAabAAAbabbAaBABAbabbAAAbbbbabBBAbbBaabBAAAbBBBbBbbAbbbBabbBABaBAaAAAbBbaABabBAbAAbBbbAbAbBaabAbBBbaaaaBaBbbABBBaaabBaBABAbBabBbbAABBbaBAba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 5 ...
result:
ok 500000 lines
Test #4:
score: 0
Accepted
time: 366ms
memory: 84168kb
input:
500 ababbBbBabaaBAbabBbbBBAAABabBbBAAABbaBbBAAbabaBaAAaabAaABBBabababAAbaaAbbAAabAAbBbaabbBbaAAABaAaBbbBbabBAABBaabbAabbBabbbAbABaBAABaBbAaaBABBbBAAbbbBabbABABAaAaAAAbaAabBbBaaaaAAAAAabaBBAAABAbbabAaBAbAaaBBbABbBBbaaAaAaBBbaBbabBbBABbaaBbAaabBABaBBbAAaaBABBAaaABAbbaaAaBaAAbAbbbbbaabBabaBbaabaAbaBaaa...
output:
386 327 309 141 424 175 186 273 45 498 99 262 478 149 424 444 49 267 233 388 359 310 203 81 498 12 97 295 400 351 352 407 310 471 291 479 448 203 267 60 223 458 421 391 5 470 212 253 99 281 167 451 154 86 299 434 370 255 383 207 258 310 487 380 6 368 235 137 334 141 50 128 29 478 448 223 466 345 407...
result:
ok 500000 lines
Test #5:
score: 0
Accepted
time: 353ms
memory: 92196kb
input:
10000 BaBbAAaaaaBAbbbbbaBbaaAbaaaabAaaaAAbabBAbaaBABaaabaAbBBaBBABAbabBAbaaAAaAABABbbbABBaBBaABbbAAbBabaAbaBBaAbabaaAAAabAbAABAabBbBaBaAaAbbBAAABbbabAaABABaBbaAABBbbBAABbbbAaABaAaaABAbbbABAabbaAaaBbbbBaBBbAaaabbaBbaaAbabBabaBaAAAbBAabbBAbabAAbbBBBbBAAaBBbBBAbaaaAbBaaBAAbbaAbbbBAbaAaaAbBBAaBabBaaaBab...
output:
-1 5219 4322 2614 7302 1876 -1 5584 2861 3586 4821 6579 6706 1605 7878 886 9218 293 167 7298 5146 6860 2921 8263 4330 9578 7472 6086 5537 4890 8285 58 9733 -1 3157 262 9533 6943 8285 2837 451 6494 7918 8912 2187 9832 4487 2077 871 210 951 1761 6892 4304 6634 9572 9544 5744 4015 7418 7804 5928 3611 8...
result:
ok 500000 lines
Test #6:
score: 0
Accepted
time: 443ms
memory: 99840kb
input:
100000 aabAbBbaBAaabbbbbaAAABaaabbBaBAAaBabbBAbBbbBbbbaaaABaaBaBbBABBBbabBAABbabbAaaaBBaAAbABaBABAABbBAbBAAAbaBaabbAAABaBAaaaBBbBbaBabAbBBaaabaaaaBbBaAaAbAbbBaABaabBbBaAAaAaaBbbAbbaaBBbbbaAaAabaBaAaaBaAAbbBabBaBAbAaabAbbbAbaAbBbaABABAaBBABAaABBBBABAaBAbbbaBbaAABBaAabaAbaAaabAAAbbbaBBbBaaaaAaaAABbBaa...
output:
35335 42708 80231 -1 52892 27828 25395 21105 26112 55093 16568 16170 -1 73256 -1 82801 58592 52120 48659 -1 -1 -1 92581 -1 67746 9463 50384 69443 71368 -1 62536 83524 71293 88216 83685 45630 5450 969 3140 19286 79236 80564 33058 44088 24142 -1 40385 68116 -1 20399 78247 52636 37514 -1 54565 44272 75...
result:
ok 500000 lines
Test #7:
score: -100
Wrong Answer
time: 504ms
memory: 104912kb
input:
500000 AaAAaaAaaaAaaaaaAaAAAaaaaAAaAAAaaAAAaAaaaaAaAaaaAaAaAAaAAaAaaAaaAaAAAAAAAAAAAAaAaAAAaAaAAAAAaaaAaAAAaAaaaAaaAaaaaaaAaaaaAaAaaAAaAAaaAAAaAaaaaaaaAaAaAaAaaAAaaaAAaAaaAAAaaaaaaaAAaAAaAaaaaaAAaAaAaaAAaaaAAaaaAaAAaaaAaAaaAAAaaAAAaAaaaaaaaaaAaAaAaAAAaaAAAAaAaAAAAAAaAAAaAaaaaaaAAaAaaAAaAAAaaaAaAAaAA...
output:
243806 -1 -1 -1 292615 -1 -1 43384 255164 -1 -1 -1 -1 -1 -1 -1 -1 230079 -1 -1 -1 210028 -1 -1 93192 -1 -1 -1 -1 -1 -1 -1 281276 -1 494439 264308 207979 -1 -1 -1 -1 -1 -1 -1 -1 394555 -1 294865 -1 -1 -1 -1 -1 407843 -1 378537 -1 134129 122684 -1 -1 -1 -1 -1 -1 142146 -1 -1 11972 -1 -1 -1 -1 -1 -1 -1...
result:
wrong answer 1st lines differ - expected: '3', found: '243806'