Submission #753345

#TimeUsernameProblemLanguageResultExecution timeMemory
753345keta_tsimakuridzeSum Zero (RMI20_sumzero)C++14
61 / 100
321 ms29696 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 + 5, mod = 1e9 + 7; // !
int t, R[N][5];
ll a[N];
map<ll,int> f;
main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i]; a[i] += a[i - 1];
    }
    int mn = n + 1;
    for(int j = 0; j <= 4; j++) R[n + 1][j] = n + 1;
    vector<int> x(n + 5);
    for(int i = n; i >= 0; i--) {
        if(f[a[i]]) mn = min(mn, f[a[i]]);
        x[i] = mn;
        f[a[i]] = i;
    }
    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 = 3; 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 * 5 + 4; j++) {
            for(int i = 0; i <= n; i++) {
                R[i][j % 5] = R[R[i][(j % 5 + 4) % 5]][(j % 5 + 4) % 5];
            }
        }
        for(int i = 1; i <= q; i++) {
            for(int j = 4; j >= 0; j--) if(R[l[i]][j] <= r[i]) ans[i] += 1 << (I * 5 + 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...