이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
const int HALF = 5e8 + 4;
struct seg {
int s, e, m, v, lazy;
seg *l, *r;
seg(int _s, int _e): s(_s), e(_e), m(_s+_e>>1), v(e-s+1), lazy(1), l(NULL) {}
void create() {
if(!l) l=new seg(s,m), r=new seg(m+1,e);
}
int val() {return v*lazy%MOD;}
void up(int x, int y, int u) {
if(s==x&&e==y) {lazy=lazy*u%MOD; return;}
create();
if(y<=m) l->up(x,y,u);
else if(x>m) r->up(x,y,u);
else l->up(x,m,u), r->up(m+1,y,u);
v=(l->val())+(r->val()); if(v>=MOD) v-=MOD;
}
void res() {
v=e-s+1;
lazy=1;
if(l) l->res(), r->res();
}
};
main() {
int n; cin >> n;
int a[n], b[n];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
seg sl(1,1<<30), sr(1,1<<30);
int ansl[n], ansr[n];
int ans = 0;
for(int i=0;i<n;i++) {
if(a[i]>b[i]) swap(a[i],b[i]);
sl.up(1,a[i],0);
sl.up(a[i]+1,b[i],HALF);
ans-=sl.val();
}
sl.res();
for(int i=n;i--;) {
sl.up(1,a[i],0);
sl.up(a[i]+1,b[i],HALF);
ans-=sl.val();
}
for(int i=0;i<n;i++) ans-=(HALF*(a[i]+b[i]))%MOD;
ans += (n<<30) + n * sl.val();
ans %= MOD; if(ans<0) ans+=MOD;
for(int i=0;i<n;i++) {ans<<=1; if(ans>=MOD) ans-=MOD;}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In constructor 'seg::seg(long long int, long long int)':
Main.cpp:9:41: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
9 | seg(int _s, int _e): s(_s), e(_e), m(_s+_e>>1), v(e-s+1), lazy(1), l(NULL) {}
| ~~^~~
Main.cpp: At global scope:
Main.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
28 | main() {
| ^~~~
Main.cpp: In function 'int main()':
Main.cpp:34:6: warning: unused variable 'ansl' [-Wunused-variable]
34 | int ansl[n], ansr[n];
| ^~~~
Main.cpp:34:15: warning: unused variable 'ansr' [-Wunused-variable]
34 | int ansl[n], ansr[n];
| ^~~~
# | 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... |