이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define pb push_back
#define pii pair <int,int>
using namespace std;
const int N = 4e5 + 2;
int p[N],l,r,res,mid,path[N],id;
vector <int> v[N];
vector <pii> qr[N];
unordered_map <int,int> last;
void dfs(int x){
p[x] = -1;
path[++id] = x;
for (auto [y,i]: qr[x]){
l = 1; r = id; res=-1;
while (l <= r){
mid = (l + r)/2;
if (path[mid] <= y){
res = mid;
r = mid - 1;
}else{
l = mid + 1;
}
}
last[i] = id - res;
}
for (int to: v[x])
dfs(to);
--id;
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,i;
cin>>n;
for(i=1;i<=n;i++)
cin>>p[i];
for (i = n; i >= 1; i--){
p[i]+=p[i+1];
last[p[i]] = 1e9;
}
last[0] = n + 1;
int k = 1e9;
for (i = n; i >= 1; i--){
k = min(k,last[p[i]]);
if (k != 1e9) v[k].pb(i);
last[p[i]] = i;
}
int q;
cin>>q;
for (i = 1; i <= q; i++){
cin>>l>>r;
qr[l].pb({r + 1,i});
}
id=0;
for (i = n+1; i >= 1; i--){
if (p[i] != -1) dfs(i);
}
for (i = 1; i <= q; i++)
cout<<last[i]<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
sumzero.cpp: In function 'void dfs(int)':
sumzero.cpp:20:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
20 | for (auto [y,i]: qr[x]){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |