제출 #754083

#제출 시각아이디문제언어결과실행 시간메모리
754083keta_tsimakuridzeSum Zero (RMI20_sumzero)C++14
22 / 100
147 ms37908 KiB
#include<bits/stdc++.h> #define f first #define s second #define pii pair<int,int> #define Pii pair<int, pair<int,int>> #define ll long long using namespace std; const int N = 4e5 + 5, mod = 1e9 + 7; // ! int t, ans[N]; ll a[N]; vector<int> V[N], p; unordered_map<ll,int> f; vector<Pii> v[N]; void dfs(int u) { p.push_back(u); for(int i = 0; i < V[u].size(); i++) dfs(V[u][i]); p.pop_back(); for(int I = 18; I >= 0; I--) { for(int i = (int)v[u].size() - 1; i >= 0; i--) { Pii x = v[u][i]; if(x.f != I) continue; swap(v[u][i], v[u].back()); v[u].pop_back(); if(x.f < 0) continue; if((int)p.size() >= (1 << x.f) && p[(int)p.size() - (1 << x.f)] <= x.s.s) ans[x.s.f] += 1 << x.f, v[p[(int)p.size() - (1 << x.f)]].push_back({x.f - 1, x.s}); else if(x.f) v[u].push_back({x.f - 1, x.s}); } } // p.push_back(u); } main(){ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); int n, q; cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; } cin >> q; int mn = n + 1; for(int i = n; i >= 0; i--) { if(f[a[i]]) mn = min(mn, f[a[i]]); V[mn].push_back(i); f[a[i]] = i; } for(int i = 1; i <= q; i++) { int l, r; cin >> l >> r; --l; v[l].push_back({18, {i, r}}); } dfs(n + 1); for(int i = 1; i <= q; i++) cout << ans[i] << "\n"; }

컴파일 시 표준 에러 (stderr) 메시지

sumzero.cpp: In function 'void dfs(int)':
sumzero.cpp:16:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i = 0; i < V[u].size(); i++) dfs(V[u][i]);
      |                    ~~^~~~~~~~~~~~~
sumzero.cpp: At global scope:
sumzero.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...