Submission #399206

#TimeUsernameProblemLanguageResultExecution timeMemory
399206abacabaSum Zero (RMI20_sumzero)C++14
61 / 100
251 ms11892 KiB
// 石室詩士施氏, 嗜獅, 誓食十獅。 // 氏時時適市視獅。 // 十時, 適十獅適市。 // 是時, 適施氏適市。 // 氏視是十獅, 恃矢勢, 使是十獅逝世。 // 氏拾是十獅屍, 適石室。 // 石室濕, 氏使侍拭石室。 // 石室拭, 氏始試食是十獅。 // 食時, 始識是十獅, 實十石獅屍。 // 試釋是事。 #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define pb push_back #define ppb pop_back #define mp make_pair #define f first #define se second template <typename T> void Max(T &a, T b) { a = max(a, b); } template <typename T> void Min(T &a, T b) { a = min(a, b); } const int inf = 0x3f3f3f3f; const int N = 1e5 + 15; int n, q, p[N], to[N]; map <int, int> last; vector <int> qs[N]; int ans[N], d[N], l, r, mid; int st[N], sz; int R[N]; int prv[N], head[N]; void dfs(int v) { st[sz++] = v; while(!qs[v].empty()) { l = 0, r = sz - 1; while(l <= r) { mid = l + r >> 1; if(st[mid] <= R[qs[v].back()]) r = mid - 1, Max(ans[qs[v].back()], d[v] - d[st[mid]]); else l = mid + 1; } qs[v].ppb(); } for(int to = head[v]; to != -1; to = prv[to]) { d[to] = d[v] + 1; dfs(to); } --sz; } int main() { memset(head, -1, sizeof(head)); memset(prv, -1, sizeof(prv)); ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0); // freopen("input.txt", "r", stdin); cin >> n; for(int i = 1; i <= n; ++i) { cin >> p[i]; p[i] += p[i-1]; } for(int i = 0; i <= n + 1; ++i) to[i] = n + 1; for(int i = n; i >= 0; --i) { if(last.count(p[i])) Min(to[i], last[p[i]]); Min(to[i], to[i+1]); prv[i] = head[to[i]]; head[to[i]] = i; last[p[i]] = i; } cin >> q; for(int i = 1; i <= q; ++i) { int l; cin >> l >> R[i]; qs[l - 1].pb(i); } dfs(n + 1); for(int i = 1; i <= q; ++i) cout << ans[i] << endl; return 0; }

Compilation message (stderr)

sumzero.cpp: In function 'void dfs(int)':
sumzero.cpp:46:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |    mid = l + r >> 1;
      |          ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...