Submission #251471

# Submission time Handle Problem Language Result Execution time Memory
251471 2020-07-21T10:45:09 Z 2qbingxuan Lollipop (POI11_liz) C++14
Compilation error
0 ms 0 KB
#include <cstdio>
const int N = 1000025;
inline int max(int a, int b){return a>b ? a : b;}
inline int min(int a, int b){return a<b ? a : b;}
int n, q, v[N], sum[N];
int Z[N], lb[N*2];
char s[N];
signed main() {
  	scanf("%d%d%s", &n, &q, s);
    for(int i = 0; i < n; i++) v[i] = (s[i]=='T' ? 2 : 1);
    for(int i = 0; i < n; i++) sum[i+1] = sum[i] + v[i];
    for(int i = 1, j = 0; i <= n*2; i++) {
        while(j < n && sum[j] < i) ++j;
        lb[i] = j;
    }
    for(int i = 1, j = 0, r = 0; i < n; i++) {
        Z[i] = max(0, min(r-i, Z[i-j]));
        while(i+Z[i] < n && v[Z[i]] == v[i+Z[i]]) ++Z[i];
        if(i+Z[i] > r) j = i, r = i+Z[i];
    }
    Z[0] = n;
    while(q--) {
        int k;
        cin >> k;
        int x = lb[k];
        if(sum[x] == k) cout << 1 << ' ' << x << '\n';
        else {
            // sum[x] == k+1
            int L = Z[x]; // v[0:Z[x]-1] = v[x:x+Z[x]-1]
            // v[Z[x]] != v[x+Z[x]]
            int R = x+Z[x];
            /* debug(L, R); */
            if(v[L] == 1)
                --R;
            ++L;
            if(R >= n || sum[R+1] - sum[L] != k) cout << "NIE\n";
            else cout << L+1 << ' ' << R+1 << '\n';
        }
    }
}

Compilation message

liz.cpp: In function 'int main()':
liz.cpp:24:9: error: 'cin' was not declared in this scope
         cin >> k;
         ^~~
liz.cpp:24:9: note: suggested alternative: 'min'
         cin >> k;
         ^~~
         min
liz.cpp:26:25: error: 'cout' was not declared in this scope
         if(sum[x] == k) cout << 1 << ' ' << x << '\n';
                         ^~~~
liz.cpp:36:50: error: 'cout' was not declared in this scope
             if(R >= n || sum[R+1] - sum[L] != k) cout << "NIE\n";
                                                  ^~~~
liz.cpp:37:18: error: 'cout' was not declared in this scope
             else cout << L+1 << ' ' << R+1 << '\n';
                  ^~~~
liz.cpp:9:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d%d%s", &n, &q, s);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~