QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#772233#8079. Range Periodicity QueryWaterSunWA 1122ms185380kbC++144.4kb2024-11-22 17:44:222024-11-22 17:44:22

Judging History

你现在查看的是最新测评结果

  • [2024-11-22 17:44:22]
  • 评测
  • 测评结果:WA
  • 用时:1122ms
  • 内存:185380kb
  • [2024-11-22 17:44:22]
  • 提交

answer

#include <bits/stdc++.h>
#define re register
#define fst first
#define snd second
#define ull unsigned long long

using namespace std;

typedef pair<int,int> pii;
const int N = 5e5 + 10;
const ull base = 102401027,mod = 1e9 + 7;
int n,m,q,arr[N];
char s[N]; ull pw[N],hs[N];
int L[N],R[N],ans[N];
pii lim[N]; bool vis[N];

struct Query{
    int k,l,r,id;

    bool friend operator <(const Query &a,const Query &b){
        return a.k > b.k;
    }
}Q[N];

inline int read(){
    int r = 0,w = 1;
    char c = getchar();
    while (c < '0' || c > '9'){
        if (c == '-') w = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9'){
        r = (r << 3) + (r << 1) + (c ^ 48);
        c = getchar();
    }
    return r * w;
}

inline void init(int n){
    deque<char> q; pw[0] = 1;
    // cerr << n << " sbsb\n";
    // return;
    for (re int i = 1;i <= n;i++) pw[i] = pw[i - 1] * base % mod;
    for (re int i = 1;i <= n;i++){
        if ('a' <= s[i] && s[i] <= 'z') q.push_front(s[i]);
        else q.push_back(s[i] + 32);
    }
    for (re int i = 1;i <= n;i++){
        hs[i] = (hs[i - 1] * base + q.front()) % mod;
        q.push_back(q.front()); q.pop_front();
    }
    for (re int i = n;i;i--){
        if (i == n) L[i] = 1,R[i] = n;
        else{
            L[i] = L[i + 1],R[i] = R[i + 1];
            if ('a' <= s[i + 1] && s[i + 1] <= 'z'){
                L[i]++; q.pop_front();
            }
            else{
                R[i]--; q.pop_back();
            }
        }
    }
    // for (re int i = 1;i <= n;i++) cerr << L[i] << " " << R[i] << " ???\n";
}

inline ull get(int l,int r){
    return (hs[r] - hs[l - 1] * pw[r - l + 1] % mod + mod) % mod;
}

struct{
    #define ls(u) (u << 1)
    #define rs(u) (u << 1 | 1)
    #define v(u) (tr[u].v)

    struct node{
        int l,r;
        vector<pii> v;
    }tr[N << 2];

    inline void build(int u,int l,int r){
        tr[u] = {l,r};
        if (l == r) return;
        int mid = l + r >> 1;
        build(ls(u),l,mid); build(rs(u),mid + 1,r);
    }

    inline void modify(int u,int l,int r,pii k){
        if (l <= tr[u].l && tr[u].r <= r) return v(u).push_back(k),void();
        int mid = tr[u].l + tr[u].r >> 1;
        if (l <= mid) modify(ls(u),l,r,k);
        if (r > mid) modify(rs(u),l,r,k);
    }

    inline void update(int u,int x,int lim){
        // cerr << u << " " << tr[u].l << " " << tr[u].r << " " << x << " " << arr[x] << " " << lim << " sbbs\n";
        while (!v(u).empty()){
            pii t = v(u).back(); v(u).pop_back();
            if (vis[t.snd]) continue;
            if (t.fst >= arr[x]){
                if (t.fst <= lim) ans[t.snd] = arr[x],vis[t.snd] = true;
                else{
                    v(u).push_back(t); break;
                }
            }
            // cerr << u << " " << x << " " << arr[x] << " " << lim << " " << t.fst << " " << t.snd << " ???\n";
        }
        if (tr[u].l == tr[u].r) return;
        int mid = tr[u].l + tr[u].r >> 1;
        if (x <= mid) update(ls(u),x,lim);
        else update(rs(u),x,lim);
    }

    #undef ls
    #undef rs
    #undef v
}T;

int main(){
    memset(ans,-1,sizeof(ans));
    n = read(); scanf("%s",s + 1); init(n);
    m = read(); T.build(1,1,m);
    for (re int i = 1;i <= m;i++){
        arr[i] = read();
        int l = arr[i],r = n;
        // cerr << arr[i] << " begin:\n";
        while (l < r){
            int mid = l + r + 1 >> 1;
            int len = mid - arr[i];
            // cerr << mid << " " << len << " " << get(L[mid],L[mid] + len - 1) << " " << get(R[mid] - len + 1,R[mid]) << " ???\n";
            if (get(L[mid],L[mid] + len - 1) == get(R[mid] - len + 1,R[mid])) l = mid;
            else r = mid - 1;
        }
        lim[i] = {i,l};
        // cerr << arr[lim[i].fst] << " " << lim[i].snd << " !!!\n";
    }
    // return 0;
    q = read();
    for (re int i = 1,k,l,r;i <= q;i++){
        k = read(),l = read(),r = read();
        Q[i] = {k,l,r,i};
    }
    sort(Q + 1,Q + q + 1);
    sort(lim + 1,lim + m + 1,[](const pii &a,const pii &b){
        return arr[a.fst] < arr[b.fst];
    });
    // cerr << "====\n"; return 0;
    for (re int i = 1;i <= q;i++) T.modify(1,Q[i].l,Q[i].r,{Q[i].k,Q[i].id});
    for (re int i = 1;i <= m;i++) T.update(1,lim[i].fst,lim[i].snd);
    for (re int i = 1;i <= q;i++) printf("%d\n",ans[i]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 79844kb

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: 158ms
memory: 128176kb

input:

200000
BAbBbBabBBbbABbbaBbaaabaBBAbBbBAAAAABBaBaAAabBAAbABaaBABAabAAAbabbAaBABAbabbAAAbbbbabBBAbbBaabBAAAbBBBbBbbAbbbBabbBABaBAaAAAbBbaABabBAbAAbBbbAbAbBaabAbBBbaaaaBaBbbABBBaaabBaBABAbBabBbbAABBbaBAbaBAbAAABABAbaabbaAAaBAbAbAbBBbaaaAaBaaABBbBAAaAAAaaABbbaAbAaBbaAaaababbaBbaAAAAAAabbBaAabbbaBBAAaABb...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
61006
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 500000 lines

Test #3:

score: 0
Accepted
time: 823ms
memory: 182572kb

input:

10
baaAaAAaAA
500000
6 8 2 3 1 8 7 3 9 4 1 6 9 4 10 10 4 3 1 7 4 3 9 7 1 2 9 3 3 1 10 8 1 6 4 1 6 10 1 5 1 8 9 9 7 3 6 3 9 1 7 6 7 7 9 10 3 2 4 10 7 3 7 1 5 3 5 1 10 1 3 2 2 4 2 3 4 10 5 2 7 10 5 6 8 9 10 6 9 7 5 4 5 4 4 2 5 8 1 9 1 2 10 8 2 5 6 6 6 4 3 1 2 2 3 5 7 4 5 7 5 8 1 8 9 7 6 3 10 7 5 4 8 8...

output:

5
4
4
2
6
3
3
4
6
3
1
6
4
5
3
5
2
5
4
4
2
5
3
5
5
1
2
5
3
5
4
3
5
6
4
5
4
6
4
6
4
1
5
4
4
3
5
3
3
4
5
5
5
4
1
6
5
5
4
4
2
4
3
5
4
5
1
5
1
1
4
4
5
4
4
3
3
4
2
4
4
4
2
4
6
5
2
5
4
3
4
2
4
5
5
4
6
1
2
6
4
5
6
1
1
3
2
3
1
4
4
3
4
4
4
3
6
5
4
5
5
4
1
2
3
4
5
4
4
4
3
6
4
4
4
2
3
3
3
3
3
6
3
5
3
4
6
3
4
5
...

result:

ok 500000 lines

Test #4:

score: 0
Accepted
time: 939ms
memory: 182536kb

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: 1002ms
memory: 182732kb

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: -100
Wrong Answer
time: 1122ms
memory: 185380kb

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
48737
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:

wrong answer 27th lines differ - expected: '50384', found: '48737'