제출 #597230

#제출 시각아이디문제언어결과실행 시간메모리
597230CaroLindaSum Zero (RMI20_sumzero)C++14
100 / 100
211 ms15108 KiB
#include <bits/stdc++.h> #define ll long long const int LOG = 20; const int MAXN = 4e5+10; using namespace std; int N, Q, T; ll C[MAXN]; int d[MAXN], l[MAXN], r[MAXN]; int dp[MAXN]; int ans[MAXN]; int id[MAXN]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> N; for(int i = 1; i <= N; i++) cin >> C[i], C[i] += C[i-1]; iota(id, id+1+N, 0); sort(id, id+1+N, [&](int a, int b){ if(C[a] == C[b]){ return a < b; } return C[a] < C[b]; }); for(int i= N; i > 0; i--){ if(C[id[i-1]] == C[id[i]]){ dp[id[i]] =id[i-1]; } else dp[id[i]] = -1; } dp[0] = 0; for(int i = 1; i <= N; i++){ if(dp[i] != -1){ d[i] = d[dp[i]]+1; if( (d[i-1] == d[i] && dp[i-1] > dp[i]) || d[i-1] > d[i] ){ d[i] = d[i-1]; dp[i] = dp[i-1]; } } else{ d[i] = d[i-1]; dp[i] = dp[i-1]; } } cin >> Q; for(int i = 1; i <= Q; i++){ cin >> l[i] >> r[i]; ans[i] = d[r[i]]-d[l[i]-1]; } int toGet = 0, toFill = 1; for(int i = 0; i < LOG; i++){ for(int j = 1; j <= Q; j++){ if((1<<i)&ans[j]){ r[j] = dp[r[j]]; } } for(int j= 1; j <= N; j++) d[j] = dp[dp[j]]; for(int j = 1; j <= N; j++) dp[j] = d[j]; } for(int i = 1; i <= Q; i++) cout << ans[i]-(r[i] < l[i]-1) << "\n"; }

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

sumzero.cpp: In function 'int main()':
sumzero.cpp:66:6: warning: unused variable 'toGet' [-Wunused-variable]
   66 |  int toGet = 0, toFill = 1;
      |      ^~~~~
sumzero.cpp:66:17: warning: unused variable 'toFill' [-Wunused-variable]
   66 |  int toGet = 0, toFill = 1;
      |                 ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...