제출 #684619

#제출 시각아이디문제언어결과실행 시간메모리
684619penguin133Sum Zero (RMI20_sumzero)C++17
61 / 100
114 ms13200 KiB
#include <bits/stdc++.h> using namespace std; //#define int long long #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif int n, A[100005], q, lft[100005]; int par[20][100005]; map <int, int> mp; void solve(){ cin >> n; for(int i=1;i<=n;i++)cin >> A[i]; mp[0] = 0; int cur = 0; for(int i=1;i<=n;i++){ cur += A[i]; if(mp.find(cur) == mp.end())lft[i] = -1; else lft[i] = mp[cur]; mp[cur] = i; } lft[0] = -1; for(int i=1;i<=n;i++)lft[i] = max(lft[i], lft[i-1]); for(int i=0;i<=n;i++)par[0][i] = lft[i]; for(int i=1;i<=19;i++)for(int j=0;j<=n;j++)par[i][j] = (par[i-1][j] != -1 ? par[i-1][par[i-1][j]] : -1); cin >> q; while(q--){ int l, r; cin >> l >> r; int tmp = r, ans = 0; for(int i=19;i>=0;i--){ if(par[i][tmp] >= l - 1)tmp = par[i][tmp], ans += (1 << i); } cout << ans << '\n'; } } main(){ ios::sync_with_stdio(0);cin.tie(0); int tc = 1; //cin >> tc; for(int tc1=1;tc1<=tc;tc1++){ // cout << "Case #" << tc1 << ": "; solve(); } }

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

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