이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define lf double
#define ll long long
#define ull unsigned ll
#define ii pair<int,int>
#define li pair<ll,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define iiii2 pair<int,iii>
#define lii pair<ll,ii>
#define lolo pair<ll,ll>
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define umin(x,y) x=min(x,y)
#define umax(x,y) x=max(x,y)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define MOD 1000000007
#define inf 1000000001
#define N pw(21)
#define LOG 20
#define magic 100
#define MAX 1000005
#define KOK 350
#define EPS 0.000000000001
#define pw(x) (1<<(x))
#define PI 3.1415926535
using namespace std;
struct SEG {
int mn[4],cnt[4];
} S[N*4];
int n,x;
int lazy[N*4],pos[N],match[N];
bool ok[N];
ll NO;
void push(int node,int bas,int son) {
for(int i=0;i<4;i++) {
S[node*2].cnt[i]+=lazy[node];
S[node*2+1].cnt[i]+=lazy[node];
}
lazy[node*2]+=lazy[node];
lazy[node*2+1]+=lazy[node];
lazy[node]=0;
}
SEG merge(SEG A,SEG B) {
SEG result;
for(int i=0;i<4;i++) {
result.cnt[i]=0;
result.mn[i]=min(A.mn[i],B.mn[i]);
if(A.mn[i]==result.mn[i]) result.cnt[i]+=A.cnt[i];
if(B.mn[i]==result.mn[i]) result.cnt[i]+=B.cnt[i];
}
return result;
}
SEG get(int node,int bas,int son,int x,int y) {
if(bas>=x && son<=y) return S[node];
push(node,bas,son);
if(orta>=x) {
if(orta+1<=y) {
return merge(get(node*2,bas,orta,x,y),get(node*2+1,orta+1,son,x,y));
}
else return get(node*2,bas,orta,x,y);
}
else return get(node*2+1,orta+1,son,x,y);
}
void up(int node,int bas,int son,int x,int y,int val) {
if(bas>y || son<x) return ;
if(bas>=x && son<=y) {
for(int i=0;i<4;i++) S[node].mn[i]+=val;
lazy[node]+=val;
return ;
}
push(node,bas,son);
up(node*2,bas,orta,x,y,val);
up(node*2+1,orta+1,son,x,y,val);
S[node]=merge(S[node*2],S[node*2+1]);
}
void build(int node,int bas,int son) {
if(bas==son) {
for(int i=0;i<4;i++) S[node].cnt[i]=S[node].mn[i]=1;
S[node].mn[bas%4]=0;
return ;
}
build(node*2,bas,orta);
build(node*2+1,orta+1,son);
S[node]=merge(S[node*2],S[node*2+1]);
}
int main() {
#if 0
freopen("input.txt","r",stdin);
#endif
scanf("%d",&n);
for(int i=1;i<=pw(n);i++) {
scanf("%d",&x);
pos[x]=i;
}
for(int i=0;i<pw(n);i++) {
match[pos[i]]=pos[pw(n)-1-i];
}
build(1,1,pw(n));
for(int i=1;i<=pw(n);i++) {
if(!ok[match[i]]) {
up(1,1,pw(n),1,i,1);
}
else {
up(1,1,pw(n),1,match[i],-1);
up(1,1,pw(n),match[i]+1,i,1);
}
SEG RES=get(1,1,pw(n),1,i);
if(RES.mn[(i+1)%4]==0) NO+=RES.cnt[(i+1)%4];
ok[i]=1;
//dbg(NO);
}
printf("%lld",1ll*pw(n)*(pw(n)+1)/2-NO);
}
컴파일 시 표준 에러 (stderr) 메시지
dojave.cpp: In function 'int main()':
dojave.cpp:160:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
dojave.cpp:164:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&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... |
# | 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... |