제출 #754057

#제출 시각아이디문제언어결과실행 시간메모리
754057keta_tsimakuridzeSum Zero (RMI20_sumzero)C++17
0 / 100
28 ms29140 KiB
#include<bits/stdc++.h> #define f first #define s second #define int long long #define pii pair<int,int> #define Pii pair<int, pair<int,int>> using namespace std; const int N = 4e5 + 5, mod = 1e9 + 7; // ! int t, ans[N], a[N]; set<pair<int, pair<int,int> >> v[N]; vector<int> V[N], p; map<int,int> f; void dfs(int u) { p.push_back(u); for(int i = 0; i < V[u].size(); i++) dfs(V[u][i]); p.pop_back(); while(v[u].size()) { Pii x = *--v[u].end(); v[u].erase(x); 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)]].insert({x.f - 1, x.s}); else if(x.f) v[u].insert({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].insert({18, {i, r}}); } dfs(n + 1); for(int i = 1; i <= q; i++) cout << ans[i] << "\n"; }

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

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