답안 #433259

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433259 2021-06-19T11:06:32 Z parsabahrami Dabbeh (INOI20_dabbeh) C++17
25 / 100
2000 ms 430432 KB
#include <bits/stdc++.h>
#pragma GCC optimize("no-stack-protector, unroll-loops, fast-math, Ofast")
#pragma GCC target("avx,avx2")

using namespace std;
     
typedef long long int ll;
typedef pair<int, int> pii;
  
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second
     
const int N = 3e5 + 10, MOD[] = {(int) 1e9 + 9, (int) 1e9 + 7};
struct pair_hash {
    template <class T1, class T2>
    size_t operator () (const std::pair<T1,T2> &p) const {
        auto h1 = std::hash<T1>{}(p.first);
        auto h2 = std::hash<T2>{}(p.second);
        return h1 ^ h2;  
    }
};

int pw[2][N], H[2][N], dp[19][N], rmq[19][19][N], lg[N], n, m, q, base[] = {37, 31}; 
char S[N * 2]; 
unordered_map<pii, int, pair_hash> mp;
pii get_hash(int l, int r) {
    pii h = {(H[0][r] - 1ll * H[0][l - 1] * pw[0][r - l + 1] % MOD[0] + MOD[0]) % MOD[0], 
        (H[1][r] - 1ll * H[1][l - 1] * pw[1][r - l + 1] % MOD[1] + MOD[1]) % MOD[1]};
    return h;
}
     
void build_rmq(int id) {
    for (int i = 1; i <= n; i++) {
        rmq[id][0][i] = dp[id][i];
    }
    for (int i = 1; i < 19; i++) {
        for (int j = 1; j <= n; j++) {
            if (j + (1 << i) <= n + 1) {
                rmq[id][i][j] = max(rmq[id][i - 1][j], rmq[id][i - 1][j + (1 << (i - 1))]);
            }
        }
    }
}
     
int get_max(int id, int l, int r) {
    if (r <= l) return l;
    r = min(r, n + 1);
    int x = lg[r - l];
    return max(rmq[id][x][l], rmq[id][x][r - (1 << x)]);
}
     
int main() {
    for (int i = 2; i < N; i++) 
        lg[i] = lg[i >> 1] + 1;
    pw[0][0] = pw[1][0] = 1;
    for (int i = 1; i < N; i++) 
        for (int j : {0, 1})
            pw[j][i] = 1ll * pw[j][i - 1] * base[j] % MOD[j];
    scanf("%d%d", &n, &q);
    for (int i = 1; i <= n; i++) {
        scanf("%s", S);
        pii h = {0, 0};
        for (int j = 0; S[j]; j++) {
            h = {(1ll * h.F * base[0] % MOD[0] + S[j] - 'a' + 1) % MOD[0], 
                (1ll * h.S * base[1] % MOD[1] + S[j] - 'a' + 1) % MOD[1]};
            mp[h] = 1;
        }
    }
    scanf("%s", S + 1); m = strlen(S + 1);
    for (int i = 1; i <= m; i++) {
        for (int j : {0, 1}) 
            H[j][i] = (1ll * H[j][i - 1] * base[j] % MOD[j] + S[i] - 'a' + 1) % MOD[j];
    }
    swap(n, m);
    for (int i = 1; i <= n; i++) {
        int l = i - 1, r = n + 1;
        while (r - l > 1) {
            int md = (l + r) >> 1;
            if (mp.count(get_hash(i, md))) l = md;
            else r = md;
        }
        dp[0][i] = l + 1;
    }
    for (int j = 1; j < 19; j++) {
        build_rmq(j - 1);
        for (int i = 1; i <= n; i++) {
            dp[j][i] = get_max(j - 1, i, dp[j - 1][i] + 1);
        }
    }
    for (build_rmq(18); q; q--) {
        int l, r; scanf("%d%d", &l, &r); l++;
        int ret = 0, p = l;
        for (int i = 18; ~i; i--) {
            if (get_max(i, l, p + 1) <= r) ret += 1 << i, p = get_max(i, l, p + 1);
        }
        printf("%d\n", ret > n ? -1 : ret + 1);
    }
    return 0;
}

Compilation message

Main.cpp:2:74: warning: bad option '-f unroll-loops' to pragma 'optimize' [-Wpragmas]
    2 | #pragma GCC optimize("no-stack-protector, unroll-loops, fast-math, Ofast")
      |                                                                          ^
Main.cpp:2:74: warning: bad option '-f fast-math' to pragma 'optimize' [-Wpragmas]
Main.cpp:2:74: warning: bad option '-f Ofast' to pragma 'optimize' [-Wpragmas]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
    3 | #pragma GCC target("avx,avx2")
      |                              ^
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:3:30: warning: bad option '-f fast-math' to attribute 'optimi
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4428 KB Output is correct
2 Correct 360 ms 28964 KB Output is correct
3 Correct 262 ms 21548 KB Output is correct
4 Correct 345 ms 28840 KB Output is correct
5 Correct 311 ms 24680 KB Output is correct
6 Correct 401 ms 31788 KB Output is correct
7 Correct 389 ms 34288 KB Output is correct
8 Correct 387 ms 33004 KB Output is correct
9 Correct 373 ms 30816 KB Output is correct
10 Correct 181 ms 11960 KB Output is correct
11 Correct 378 ms 32556 KB Output is correct
12 Correct 207 ms 18540 KB Output is correct
13 Correct 272 ms 24572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1653 ms 423656 KB Output is correct
2 Execution timed out 2020 ms 430432 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4428 KB Output is correct
2 Correct 360 ms 28964 KB Output is correct
3 Correct 262 ms 21548 KB Output is correct
4 Correct 345 ms 28840 KB Output is correct
5 Correct 311 ms 24680 KB Output is correct
6 Correct 401 ms 31788 KB Output is correct
7 Correct 389 ms 34288 KB Output is correct
8 Correct 387 ms 33004 KB Output is correct
9 Correct 373 ms 30816 KB Output is correct
10 Correct 181 ms 11960 KB Output is correct
11 Correct 378 ms 32556 KB Output is correct
12 Correct 207 ms 18540 KB Output is correct
13 Correct 272 ms 24572 KB Output is correct
14 Correct 1653 ms 423656 KB Output is correct
15 Execution timed out 2020 ms 430432 KB Time limit exceeded
16 Halted 0 ms 0 KB -