Submission #979007

#TimeUsernameProblemLanguageResultExecution timeMemory
979007NintsiChkhaidzeSum Zero (RMI20_sumzero)C++17
100 / 100
593 ms19068 KiB
#include <bits/stdc++.h> #define ll long long #define s second #define f first #define pb push_back #define pii pair <int,int> #pragma GCC target("avx2,popcnt") #pragma GCC optimize("O3,unroll-loops") using namespace std; const int N = 4e5 + 3; int p[N],to[N],cur[N]; pii lr[N]; unordered_map <ll,int> mp; int main(){ ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n; cin>>n; for(int i=1;i<=n;i++){ cin>>p[i]; } ll sum = 0; int t = 1e9; for (int i = n + 1; i >= 1; i--){ sum += p[i]; if (mp.find(sum) != mp.end()) { t = min(t,mp[sum]); } to[i] = t; mp[sum] = i; } int q; cin>>q; for (int i = 1; i <= q; i++){ cin >> lr[i].f >> lr[i].s; p[i] = 0; } for (int i = 18; i >= 0; i--){ for (int j = 1; j <= n+1; j++) cur[j] = to[j]; for (int j = 1; j <= i; j++) for (int k = 1; k <= n; k++) if (cur[k] <= n+1) cur[k] = cur[cur[k]]; for (int j = 1; j <= q; j++){ if (cur[lr[j].f] <= lr[j].s + 1){ lr[j].f = cur[lr[j].f]; p[j] += (1<<i); } } } for (int i=1;i<=q;i++) cout<<p[i]<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...