Submission #938629

# Submission time Handle Problem Language Result Execution time Memory
938629 2024-03-05T11:28:10 Z dubabuba Fancy Fence (CEOI20_fancyfence) C++14
15 / 100
316 ms 10868 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int, int> pii;
#define ff first
#define ss second
#define MP make_pair

const int mxn = 1e5 + 9;
const int mod = 1e9 + 7;
int a[mxn], b[mxn], p[mxn], n;
vector<pii> q;
set<int> s;

int mult(int a, int b) {
	a %= mod;
	b %= mod;
	if(a < b) swap(a, b);
	if(b == 0) return 0;
	if(b == 1) return a;
	int t = mult(a, b / 2);
	if(b % 2 == 0) return (t + t) % mod;
	return ((t + t) % mod + a) % mod;
}

int C2(int a) {
	if(a & 1) return mult(a, (a + 1) / 2);
	return mult(a / 2, a + 1);
}

signed main() {
	cin >> n;
	for(int i = 2; i <= n + 1; i++) {
		cin >> a[i];
		q.push_back(MP(a[i], i));
	}
	for(int i = 2; i <= n + 1; i++) {
		cin >> b[i];
		p[i] = p[i - 1] + b[i];
	}

	int ans = 0;
	for(int i = 2; i <= n + 1; i++) {
		int d = mult(C2(a[i]), C2(b[i]));
		ans = (ans + d) % mod;
	}

	q.push_back(MP(0, 1));
	q.push_back(MP(0, n + 2));
	sort(q.begin(), q.end());
	int t = 0;

	for(pii p : q) {
		int H = p.ff;
		int r = p.ss;
		while(t < q.size() && q[t].ff < H) {
			s.insert(-q[t].ss);
			t++;
		}
		auto it = s.upper_bound(-r);
		if(it == s.end()) continue;
		int l = -(*it);
		int W = ::p[r - 1] - ::p[l];
		int d = mult(mult(W, b[r]), C2(H));
		// cout << l << ' ' << r << ": " << d << endl;
		ans = (ans + d) % mod;
	}

	s.clear();
	t = 0;
	for(pii p : q) {
		int H = p.ff;
		int l = p.ss;
		while(t < q.size() && q[t].ff <= H) {
			s.insert(q[t].ss);
			t++;
		}
		auto it = s.upper_bound(l);
		if(it == s.end()) continue;
		int r = (*it);
		int W = ::p[r - 1] - ::p[l];
		// cout << l << ' ' << r << endl;
		int d = mult(mult(W, b[l]), C2(H));
		ans = (ans + d) % mod;
	}

	cout << ans << endl;
	return 0;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:57:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   while(t < q.size() && q[t].ff < H) {
      |         ~~^~~~~~~~~~
fancyfence.cpp:75:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |   while(t < q.size() && q[t].ff <= H) {
      |         ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 4 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 2 ms 2392 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2396 KB Output is correct
2 Correct 28 ms 3308 KB Output is correct
3 Correct 137 ms 6536 KB Output is correct
4 Correct 299 ms 10760 KB Output is correct
5 Correct 243 ms 10868 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 3 ms 2396 KB Output is correct
3 Correct 29 ms 3320 KB Output is correct
4 Correct 137 ms 6728 KB Output is correct
5 Correct 316 ms 10768 KB Output is correct
6 Correct 265 ms 10864 KB Output is correct
7 Correct 5 ms 2392 KB Output is correct
8 Correct 34 ms 3380 KB Output is correct
9 Correct 135 ms 6572 KB Output is correct
10 Incorrect 306 ms 10648 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 4 ms 2504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 4 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -