QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725645#1074. Automatic TradingTheZone100 ✓67ms8536kbC++204.0kb2024-11-08 19:11:102024-11-08 19:11:11

Judging History

This is the latest submission verdict.

  • [2024-11-08 19:11:11]
  • Judged
  • Verdict: 100
  • Time: 67ms
  • Memory: 8536kb
  • [2024-11-08 19:11:10]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define rep(i,a,b) for(int i = a; i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back
#define FS first
#define SD second
typedef pair<int, int> pii;
typedef vector<int> vi;
template<class X, class Y> X cmx(X &a, Y b) { a = max<X>(a, b); }
#define ary(k) array<int, k>

int pod = 1019, mod = 1000000033;
int pref[1000002], pot[1000002];

int hasz(int l, int r) {
    int res = pref[r] - pref[l-1] * pot[r-l+1] % mod;
    if (res < 0)
        res += mod;
    return res;
}

signed main() {
	cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit);
    pot[0] = 1;
    for (int i = 1; i <= 200000; i++) {
        pot[i] = pot[i-1] * pod % mod;
    }
    while (true) {
        string slo;
        cin >> slo;
        if (slo == "*")
            break;
        slo = "%" + slo;
        pref[0] = 0;
        for (int i = 1; i < sz(slo); i++) {
            pref[i] = pref[i-1] * pod + slo[i];
            pref[i] %= mod;
        }
        int q;
        cin >> q;
        while (q--) {
            int l, r;
            cin >> l >> r;
            l++; r++;
            int pocz = 0, kon = sz(slo) - r;
            while (pocz < kon) {
                int mid = (pocz + kon + 1) / 2;
                if (hasz(l, l + mid - 1) == hasz(r, r + mid - 1)) {
                    pocz = mid;
                } else {
                    kon = mid - 1;
                }
            }
            cout << pocz << "\n";
        }
    }
}

















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 100
Accepted
time: 67ms
memory: 8536kb

input:

GdLOucXwThisIsAGreatContestutTVdKgWIMertKThisIsAGreatContestNxUHEiOvZuVfKjqwJUuu
11
0 1
78 79
8 41
8 40
8 42
7 41
7 40
7 42
9 41
9 40
9 42
GdLOucXwThiThisThisIsAGreatContestWIMertKTTThisIsAGreatContesttstiOvZuVfKjqwJUuD
6
8 11
8 15
8 43
11 15
11 43
15 43
ThisIsAGreatContestThisIsAGreatContestThisIsA...

output:

0
1
19
0
0
0
0
0
0
0
18
3
3
3
4
4
19
61
42
23
4
42
23
4
23
4
4
19
19
19
11
2
38
2
2
36
2
17
38
17
17
21
17
36
18
18
2
1
0
0
1
0
0
0
0
19
60
40
20
40
20
20
0
0
0
19
7
7
19
79
1
1
41
1
31
1
30
1
30
1
52
9932
4992
52
0
0
0
0
0
0
0
0
0
0
0
4992
0
0
9932
0
0
52
0
0
0
4991
0
0
9931
0
0
51
0
0
52
0
0
0
499...

result:

ok 300152 lines