제출 #597359

#제출 시각아이디문제언어결과실행 시간메모리
597359pedroslreySum Zero (RMI20_sumzero)C++17
61 / 100
220 ms31456 KiB
#include <bits/stdc++.h> using namespace std; using lli = long long; const int MAXN = 4e5 + 10; const int MAXK = 20; int ant[MAXN], dp[MAXN], prof[MAXN], ls[MAXN], rs[MAXN], ds[MAXN], tmp[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; map<lli, vector<int>> mp; mp[0].push_back(0); lli sum = 0; for (int i = 1; i <= n; ++i) { int x; cin >> x; sum += x; mp[sum].push_back(i); } for (int i = 1; i <= n; ++i) ant[i] = -1; for (auto [k, xs]: mp) for (int i = 1; i < xs.size(); ++i) ant[xs[i]] = xs[i-1]; dp[0] = -1; for (int i = 1; i <= n; ++i) { if (ant[i] < dp[i-1]) dp[i] = dp[i-1]; else dp[i] = ant[i]; prof[i] = 1 + (dp[i] == -1 ? -1 : prof[dp[i]]); } int q; cin >> q; for (int i = 0; i < q; ++i) { cin >> ls[i] >> rs[i]; ds[i] = prof[rs[i]] - prof[ls[i]-1]; } for (int k = 0; k < MAXK; ++k) { for (int i = 0; i < q; ++i) if (ds[i] & (1 << k)) rs[i] = dp[rs[i]]; for (int i = 1; i <= n; ++i) if (dp[i] != -1) tmp[i] = dp[dp[i]]; else tmp[i] = -1; for (int i = 1; i <= n; ++i) dp[i] = tmp[i]; } for (int i = 0; i < q; ++i) { if (rs[i] < ls[i] - 1) cout << ds[i] - 1 << "\n"; else cout << ds[i] << "\n"; } }

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

sumzero.cpp: In function 'int main()':
sumzero.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   for (int i = 1; i < xs.size(); ++i)
      |                   ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...