Submission #753353

#TimeUsernameProblemLanguageResultExecution timeMemory
753353keta_tsimakuridzeSum Zero (RMI20_sumzero)C++14
61 / 100
330 ms28364 KiB
#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define pii pair<int,int>
using namespace std;
const int N = 4e5 + 1, mod = 1e9 + 7; // !
int t, R[N][4];
int a[N];
map<int,int> f;
main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n;
    cin >> n;
    ll all = 0;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        all += a[i];
    }
    int mn = n + 1;
    for(int j = 0; j <= 3; j++) R[n + 1][j] = n + 1;
    vector<int> x(n + 5);
    for(int i = n; i >= 0; i--) {
        if(f[all]) mn = min(mn, f[all]);
        x[i] = mn;
        f[all] = i;
        all -= a[i];
    }
    f.clear();
    int q;
    cin >> q;
    vector<int> l(q + 1), r(q + 1), ans(q + 1);
    for(int i = 1; i <= q; i++) {
        cin >> l[i] >> r[i];
        --l[i];
    }

    for(int I = 4; I >= 0; I--) {
        // i * 5 ... i * 5 + 4
        for(int i = 0; i <= n; i++) R[i][0] = x[i];
        for(int j = 1; j <= I * 4 + 3; j++) {
            for(int i = 0; i <= n; i++) {
                R[i][j % 4] = R[R[i][(j % 4 + 3) % 4]][(j % 4 + 3) % 4];
            }
        }
        for(int i = 1; i <= q; i++) {
            for(int j = 3; j >= 0; j--) if(R[l[i]][j] <= r[i]) ans[i] += 1 << (I * 4 + j), l[i] = R[l[i]][j];
        }
    }
    for(int i = 1; i <= q; i++) cout << ans[i] << "\n";
 }

Compilation message (stderr)

sumzero.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...