제출 #1004320

#제출 시각아이디문제언어결과실행 시간메모리
1004320PenguinsAreCuteFlooding Wall (BOI24_wall)C++17
70 / 100
1791 ms1048576 KiB
#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; } }; 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(); } for(int i=n;i--;) { sr.up(1,a[i],0); sr.up(a[i]+1,b[i],HALF); ans-=sr.val(); } for(int i=0;i<n;i++) ans-=(HALF*(a[i]+b[i]))%MOD; ans += (n<<30) + n * sr.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:23:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   23 | main() {
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:29:6: warning: unused variable 'ansl' [-Wunused-variable]
   29 |  int ansl[n], ansr[n];
      |      ^~~~
Main.cpp:29:15: warning: unused variable 'ansr' [-Wunused-variable]
   29 |  int ansl[n], ansr[n];
      |               ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...