# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
224567 | kshitij_sodani | Pilot (NOI19_pilot) | C++17 | 1097 ms | 111400 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
typedef long long llo;
llo par[1000001];
llo ss[1000001];
vector<llo> it[1000001];
vector<llo> tt[1000001];
llo find(llo no){
if(par[no]==no){
return no;
}
par[no]=find(par[no]);
return par[no];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
llo n,q;
cin>>n>>q;
for(llo i=0;i<n;i++){
par[i]=i;
ss[i]=0;
}
llo aa;
for(llo i=0;i<n;i++){
cin>>aa;
it[aa].pb(i);
}
llo ans2[q];
for(llo i=0;i<q;i++){
cin>>aa;
tt[aa].pb(i);
}
llo ans=0;
for(llo k=0;k<1000001;k++){
for(llo j=0;j<it[k].size();j++){
llo ind=it[k][j];
ss[ind]=1;
ans+=1;
if(ind>0){
if(ss[ind-1]>0){
llo x=find(ind-1);
ans+=ss[x];
ss[x]+=ss[ind];
par[ind]=x;
}
}
if(ind<n-1){
if(ss[ind+1]>0){
llo y=find(ind);
llo x=find(ind+1);
if(ss[x]>ss[y]){
ans+=ss[x]*ss[y];
ss[x]+=ss[y];
par[y]=x;
}
else{
ans+=ss[x]*ss[y];
ss[y]+=ss[x];
par[x]=y;
}
}
}
}
for(int j=0;j<tt[k].size();j++){
ans2[tt[k][j]]=ans;
}
}
for(llo i=0;i<q;i++){
cout<<ans2[i]<<endl;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |