Submission #1004384

# Submission time Handle Problem Language Result Execution time Memory
1004384 2024-06-21T08:25:40 Z PenguinsAreCute Flooding Wall (BOI24_wall) C++17
100 / 100
2568 ms 99964 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
const int HALF = 5e8 + 4;
vector<int> disc;
struct seg {
	int n, h; vector<int> v, lazy;
	seg(int _n): n(_n), h(64-__builtin_clzll(_n)), lazy(2*_n,1), v(2*_n) {
		for(int i=0;i<n;i++) v[i+n]=disc[i+1]-disc[i];
		for(int i=n;i--;) {v[i]=v[i<<1]+v[i<<1|1]; if(v[i]>=MOD) v[i]-=MOD;}
	}
	void calc(int x) {v[x]=(v[x<<1]+v[x<<1|1])*lazy[x]%MOD;}
	void app(int x, int k) {
		(v[x]*=k)%=MOD;
		if(x<n) (lazy[x]*=k)%=MOD;
	}
	void push(int x) {
		int s=h;
		for(x+=n;s;s--) {
			int i=x>>s;
			app(i<<1,lazy[i]);
			app(i<<1|1,lazy[i]);
			lazy[i]=1;
		}
	}
	void build(int x) {for(x+=n;x>>=1;) calc(x);}
	void up(int x, int y, int m) {
		push(x); push(y-1);
		int x0 = x, y0 = y;
		for(x+=n,y+=n;x<y;x>>=1,y>>=1) {
			if(x&1) app(x++,m);
			if(y&1) app(--y,m);
		}
		build(x0); build(y0-1);
	}
};
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];
	for(int i=0;i<n;i++) disc.push_back(a[i]),disc.push_back(b[i]);
	disc.push_back(0);
	sort(disc.begin(),disc.end());
	while(disc.size()<=(1<<20)) disc.push_back(1<<30);
	int aa[n], bb[n];
	for(int i=0;i<n;i++) {
		if(a[i]>b[i]) swap(a[i],b[i]);
		aa[i]=lower_bound(disc.begin(),disc.end(),a[i])-disc.begin();
		bb[i]=lower_bound(disc.begin(),disc.end(),b[i])-disc.begin();
	}
	seg sl(1<<20), sr(1<<20);
	int ansl[n], ansr[n];
	int ans = 0;
	for(int i=0;i<n;i++) {
		sl.up(0,aa[i],0);
		sl.up(aa[i],bb[i],HALF);
		ans-=sl.v[1];
	}
	for(int i=n;i--;) {
		sr.up(0,aa[i],0);
		sr.up(aa[i],bb[i],HALF);
		ans-=sr.v[1];
	}
	for(int i=0;i<n;i++) ans-=(HALF*(a[i]+b[i]))%MOD;
	(ans += (n<<30) + n * sl.v[1]) %= MOD;
	if(ans<0) ans+=MOD;
	for(int i=0;i<n;i++) {ans<<=1; if(ans>=MOD) ans-=MOD;}
	cout << ans;
}

Compilation message

Main.cpp: In constructor 'seg::seg(long long int)':
Main.cpp:8:27: warning: 'seg::lazy' will be initialized after [-Wreorder]
    8 |  int n, h; vector<int> v, lazy;
      |                           ^~~~
Main.cpp:8:24: warning:   'std::vector<long long int> seg::v' [-Wreorder]
    8 |  int n, h; vector<int> v, lazy;
      |                        ^
Main.cpp:9:2: warning:   when initialized here [-Wreorder]
    9 |  seg(int _n): n(_n), h(64-__builtin_clzll(_n)), lazy(2*_n,1), v(2*_n) {
      |  ^~~
Main.cpp: At global scope:
Main.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main() {
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:54:6: warning: unused variable 'ansl' [-Wunused-variable]
   54 |  int ansl[n], ansr[n];
      |      ^~~~
Main.cpp:54:15: warning: unused variable 'ansr' [-Wunused-variable]
   54 |  int ansl[n], ansr[n];
      |               ^~~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 74384 KB Output is correct
2 Correct 37 ms 74404 KB Output is correct
3 Correct 38 ms 74352 KB Output is correct
4 Correct 37 ms 74404 KB Output is correct
5 Correct 34 ms 74368 KB Output is correct
6 Correct 34 ms 74400 KB Output is correct
7 Correct 36 ms 74428 KB Output is correct
8 Correct 47 ms 74312 KB Output is correct
9 Correct 38 ms 74324 KB Output is correct
10 Correct 36 ms 74432 KB Output is correct
11 Correct 37 ms 74424 KB Output is correct
12 Correct 37 ms 74388 KB Output is correct
13 Correct 37 ms 74388 KB Output is correct
14 Correct 37 ms 74432 KB Output is correct
15 Correct 40 ms 74256 KB Output is correct
16 Correct 37 ms 74416 KB Output is correct
17 Correct 38 ms 74312 KB Output is correct
18 Correct 40 ms 74428 KB Output is correct
19 Correct 37 ms 74388 KB Output is correct
20 Correct 37 ms 74304 KB Output is correct
21 Correct 37 ms 74424 KB Output is correct
22 Correct 38 ms 74408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 74404 KB Output is correct
2 Correct 47 ms 74392 KB Output is correct
3 Correct 39 ms 74404 KB Output is correct
4 Correct 37 ms 74408 KB Output is correct
5 Correct 36 ms 74432 KB Output is correct
6 Correct 36 ms 74332 KB Output is correct
7 Correct 38 ms 74404 KB Output is correct
8 Correct 38 ms 74432 KB Output is correct
9 Correct 38 ms 74388 KB Output is correct
10 Correct 40 ms 74384 KB Output is correct
11 Correct 37 ms 74428 KB Output is correct
12 Correct 37 ms 74432 KB Output is correct
13 Correct 37 ms 74428 KB Output is correct
14 Correct 37 ms 74452 KB Output is correct
15 Correct 36 ms 74380 KB Output is correct
16 Correct 37 ms 74408 KB Output is correct
17 Correct 37 ms 74420 KB Output is correct
18 Correct 37 ms 74404 KB Output is correct
19 Correct 37 ms 74208 KB Output is correct
20 Correct 37 ms 74412 KB Output is correct
21 Correct 37 ms 74420 KB Output is correct
22 Correct 38 ms 74356 KB Output is correct
23 Correct 37 ms 74396 KB Output is correct
24 Correct 41 ms 74388 KB Output is correct
25 Correct 39 ms 74464 KB Output is correct
26 Correct 38 ms 74428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 74404 KB Output is correct
2 Correct 47 ms 74392 KB Output is correct
3 Correct 39 ms 74404 KB Output is correct
4 Correct 37 ms 74408 KB Output is correct
5 Correct 36 ms 74432 KB Output is correct
6 Correct 36 ms 74332 KB Output is correct
7 Correct 38 ms 74404 KB Output is correct
8 Correct 38 ms 74432 KB Output is correct
9 Correct 38 ms 74388 KB Output is correct
10 Correct 40 ms 74384 KB Output is correct
11 Correct 37 ms 74428 KB Output is correct
12 Correct 37 ms 74432 KB Output is correct
13 Correct 37 ms 74428 KB Output is correct
14 Correct 37 ms 74452 KB Output is correct
15 Correct 36 ms 74380 KB Output is correct
16 Correct 37 ms 74408 KB Output is correct
17 Correct 37 ms 74420 KB Output is correct
18 Correct 37 ms 74404 KB Output is correct
19 Correct 37 ms 74208 KB Output is correct
20 Correct 37 ms 74412 KB Output is correct
21 Correct 37 ms 74420 KB Output is correct
22 Correct 38 ms 74356 KB Output is correct
23 Correct 37 ms 74396 KB Output is correct
24 Correct 41 ms 74388 KB Output is correct
25 Correct 39 ms 74464 KB Output is correct
26 Correct 38 ms 74428 KB Output is correct
27 Correct 71 ms 74832 KB Output is correct
28 Correct 72 ms 74608 KB Output is correct
29 Correct 75 ms 74792 KB Output is correct
30 Correct 79 ms 74644 KB Output is correct
31 Correct 68 ms 74792 KB Output is correct
32 Correct 63 ms 74660 KB Output is correct
33 Correct 60 ms 74688 KB Output is correct
34 Correct 69 ms 74664 KB Output is correct
35 Correct 73 ms 74756 KB Output is correct
36 Correct 67 ms 74680 KB Output is correct
37 Correct 72 ms 74680 KB Output is correct
38 Correct 71 ms 74680 KB Output is correct
39 Correct 72 ms 74648 KB Output is correct
40 Correct 70 ms 74648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 74384 KB Output is correct
2 Correct 37 ms 74404 KB Output is correct
3 Correct 38 ms 74352 KB Output is correct
4 Correct 37 ms 74404 KB Output is correct
5 Correct 34 ms 74368 KB Output is correct
6 Correct 34 ms 74400 KB Output is correct
7 Correct 36 ms 74428 KB Output is correct
8 Correct 47 ms 74312 KB Output is correct
9 Correct 38 ms 74324 KB Output is correct
10 Correct 36 ms 74432 KB Output is correct
11 Correct 37 ms 74424 KB Output is correct
12 Correct 37 ms 74388 KB Output is correct
13 Correct 37 ms 74388 KB Output is correct
14 Correct 37 ms 74432 KB Output is correct
15 Correct 40 ms 74256 KB Output is correct
16 Correct 37 ms 74416 KB Output is correct
17 Correct 38 ms 74312 KB Output is correct
18 Correct 40 ms 74428 KB Output is correct
19 Correct 37 ms 74388 KB Output is correct
20 Correct 37 ms 74304 KB Output is correct
21 Correct 37 ms 74424 KB Output is correct
22 Correct 38 ms 74408 KB Output is correct
23 Correct 37 ms 74404 KB Output is correct
24 Correct 47 ms 74392 KB Output is correct
25 Correct 39 ms 74404 KB Output is correct
26 Correct 37 ms 74408 KB Output is correct
27 Correct 36 ms 74432 KB Output is correct
28 Correct 36 ms 74332 KB Output is correct
29 Correct 38 ms 74404 KB Output is correct
30 Correct 38 ms 74432 KB Output is correct
31 Correct 38 ms 74388 KB Output is correct
32 Correct 40 ms 74384 KB Output is correct
33 Correct 37 ms 74428 KB Output is correct
34 Correct 37 ms 74432 KB Output is correct
35 Correct 37 ms 74428 KB Output is correct
36 Correct 37 ms 74452 KB Output is correct
37 Correct 36 ms 74380 KB Output is correct
38 Correct 37 ms 74408 KB Output is correct
39 Correct 37 ms 74420 KB Output is correct
40 Correct 37 ms 74404 KB Output is correct
41 Correct 37 ms 74208 KB Output is correct
42 Correct 37 ms 74412 KB Output is correct
43 Correct 37 ms 74420 KB Output is correct
44 Correct 38 ms 74356 KB Output is correct
45 Correct 37 ms 74396 KB Output is correct
46 Correct 41 ms 74388 KB Output is correct
47 Correct 39 ms 74464 KB Output is correct
48 Correct 38 ms 74428 KB Output is correct
49 Correct 71 ms 74832 KB Output is correct
50 Correct 72 ms 74608 KB Output is correct
51 Correct 75 ms 74792 KB Output is correct
52 Correct 79 ms 74644 KB Output is correct
53 Correct 68 ms 74792 KB Output is correct
54 Correct 63 ms 74660 KB Output is correct
55 Correct 60 ms 74688 KB Output is correct
56 Correct 69 ms 74664 KB Output is correct
57 Correct 73 ms 74756 KB Output is correct
58 Correct 67 ms 74680 KB Output is correct
59 Correct 72 ms 74680 KB Output is correct
60 Correct 71 ms 74680 KB Output is correct
61 Correct 72 ms 74648 KB Output is correct
62 Correct 70 ms 74648 KB Output is correct
63 Correct 75 ms 74928 KB Output is correct
64 Correct 73 ms 74936 KB Output is correct
65 Correct 73 ms 74900 KB Output is correct
66 Correct 68 ms 74680 KB Output is correct
67 Correct 72 ms 74968 KB Output is correct
68 Correct 69 ms 74800 KB Output is correct
69 Correct 71 ms 74876 KB Output is correct
70 Correct 74 ms 74680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 74408 KB Output is correct
2 Correct 44 ms 74432 KB Output is correct
3 Correct 37 ms 74428 KB Output is correct
4 Correct 37 ms 74284 KB Output is correct
5 Correct 36 ms 74432 KB Output is correct
6 Correct 37 ms 74432 KB Output is correct
7 Correct 38 ms 74420 KB Output is correct
8 Correct 38 ms 74388 KB Output is correct
9 Correct 37 ms 74388 KB Output is correct
10 Correct 72 ms 74652 KB Output is correct
11 Correct 74 ms 74748 KB Output is correct
12 Correct 81 ms 74664 KB Output is correct
13 Correct 73 ms 74692 KB Output is correct
14 Correct 1644 ms 92052 KB Output is correct
15 Correct 1643 ms 91800 KB Output is correct
16 Correct 1745 ms 91800 KB Output is correct
17 Correct 1681 ms 92052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 74384 KB Output is correct
2 Correct 37 ms 74404 KB Output is correct
3 Correct 38 ms 74352 KB Output is correct
4 Correct 37 ms 74404 KB Output is correct
5 Correct 34 ms 74368 KB Output is correct
6 Correct 34 ms 74400 KB Output is correct
7 Correct 36 ms 74428 KB Output is correct
8 Correct 47 ms 74312 KB Output is correct
9 Correct 38 ms 74324 KB Output is correct
10 Correct 36 ms 74432 KB Output is correct
11 Correct 37 ms 74424 KB Output is correct
12 Correct 37 ms 74388 KB Output is correct
13 Correct 37 ms 74388 KB Output is correct
14 Correct 37 ms 74432 KB Output is correct
15 Correct 40 ms 74256 KB Output is correct
16 Correct 37 ms 74416 KB Output is correct
17 Correct 38 ms 74312 KB Output is correct
18 Correct 40 ms 74428 KB Output is correct
19 Correct 37 ms 74388 KB Output is correct
20 Correct 37 ms 74304 KB Output is correct
21 Correct 37 ms 74424 KB Output is correct
22 Correct 38 ms 74408 KB Output is correct
23 Correct 37 ms 74404 KB Output is correct
24 Correct 47 ms 74392 KB Output is correct
25 Correct 39 ms 74404 KB Output is correct
26 Correct 37 ms 74408 KB Output is correct
27 Correct 36 ms 74432 KB Output is correct
28 Correct 36 ms 74332 KB Output is correct
29 Correct 38 ms 74404 KB Output is correct
30 Correct 38 ms 74432 KB Output is correct
31 Correct 38 ms 74388 KB Output is correct
32 Correct 40 ms 74384 KB Output is correct
33 Correct 37 ms 74428 KB Output is correct
34 Correct 37 ms 74432 KB Output is correct
35 Correct 37 ms 74428 KB Output is correct
36 Correct 37 ms 74452 KB Output is correct
37 Correct 36 ms 74380 KB Output is correct
38 Correct 37 ms 74408 KB Output is correct
39 Correct 37 ms 74420 KB Output is correct
40 Correct 37 ms 74404 KB Output is correct
41 Correct 37 ms 74208 KB Output is correct
42 Correct 37 ms 74412 KB Output is correct
43 Correct 37 ms 74420 KB Output is correct
44 Correct 38 ms 74356 KB Output is correct
45 Correct 37 ms 74396 KB Output is correct
46 Correct 41 ms 74388 KB Output is correct
47 Correct 39 ms 74464 KB Output is correct
48 Correct 38 ms 74428 KB Output is correct
49 Correct 71 ms 74832 KB Output is correct
50 Correct 72 ms 74608 KB Output is correct
51 Correct 75 ms 74792 KB Output is correct
52 Correct 79 ms 74644 KB Output is correct
53 Correct 68 ms 74792 KB Output is correct
54 Correct 63 ms 74660 KB Output is correct
55 Correct 60 ms 74688 KB Output is correct
56 Correct 69 ms 74664 KB Output is correct
57 Correct 73 ms 74756 KB Output is correct
58 Correct 67 ms 74680 KB Output is correct
59 Correct 72 ms 74680 KB Output is correct
60 Correct 71 ms 74680 KB Output is correct
61 Correct 72 ms 74648 KB Output is correct
62 Correct 70 ms 74648 KB Output is correct
63 Correct 75 ms 74928 KB Output is correct
64 Correct 73 ms 74936 KB Output is correct
65 Correct 73 ms 74900 KB Output is correct
66 Correct 68 ms 74680 KB Output is correct
67 Correct 72 ms 74968 KB Output is correct
68 Correct 69 ms 74800 KB Output is correct
69 Correct 71 ms 74876 KB Output is correct
70 Correct 74 ms 74680 KB Output is correct
71 Correct 37 ms 74408 KB Output is correct
72 Correct 44 ms 74432 KB Output is correct
73 Correct 37 ms 74428 KB Output is correct
74 Correct 37 ms 74284 KB Output is correct
75 Correct 36 ms 74432 KB Output is correct
76 Correct 37 ms 74432 KB Output is correct
77 Correct 38 ms 74420 KB Output is correct
78 Correct 38 ms 74388 KB Output is correct
79 Correct 37 ms 74388 KB Output is correct
80 Correct 72 ms 74652 KB Output is correct
81 Correct 74 ms 74748 KB Output is correct
82 Correct 81 ms 74664 KB Output is correct
83 Correct 73 ms 74692 KB Output is correct
84 Correct 1644 ms 92052 KB Output is correct
85 Correct 1643 ms 91800 KB Output is correct
86 Correct 1745 ms 91800 KB Output is correct
87 Correct 1681 ms 92052 KB Output is correct
88 Correct 2458 ms 99760 KB Output is correct
89 Correct 2568 ms 99776 KB Output is correct
90 Correct 1539 ms 92152 KB Output is correct
91 Correct 1722 ms 99736 KB Output is correct
92 Correct 1575 ms 92128 KB Output is correct
93 Correct 1697 ms 92052 KB Output is correct
94 Correct 1885 ms 99964 KB Output is correct
95 Correct 1701 ms 92148 KB Output is correct
96 Correct 1858 ms 95708 KB Output is correct
97 Correct 1647 ms 95948 KB Output is correct