QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#416870#8712. Flooding Wallzhoukangyang#Compile Error//C++144.3kb2024-05-22 10:17:122024-05-22 10:17:12

Judging History

This is the latest submission verdict.

  • [2024-05-22 10:17:12]
  • Judged
  • [2024-05-22 10:17:12]
  • Submitted

answer

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define sz(a) ((int) (a).size())
#define vi vector < int >
#define me(a, x) memset(a, x, sizeof(a))
#define ull unsigned long long
#define ld __float128
#define pb emplace_back
using namespace std;
const int N = 1 << 21, mod = 1e9 + 7;
int n;
int a[N], b[N];
int arr[N], tot;
int sum1[N], sum2[N], tag[N];
void adt(int x, int w) {
	sum1[x] = (ll)sum1[x] * w % mod;
	sum2[x] = (ll)sum2[x] * w % mod;
	tag[x] = (ll)tag[x] * w % mod;
}
void push(int x) {
	if(tag[x] != 1) adt(x * 2, tag[x]), adt(x * 2 + 1, tag[x]), tag[x] = 1;
}
void upd(int x) {
	sum1[x] = (sum1[x * 2] + sum1[x * 2 + 1]) % mod;
	sum2[x] = (sum2[x * 2] + sum2[x * 2 + 1]) % mod;
}
inline void add(int x, int L, int R, int l, int r, int w) {
	if(l <= L && R <= r) return adt(x, w), void();
	int mid = (L + R) >> 1;
	push(x);
	if(l <= mid) add(x * 2, L, mid, l, r, w);
	if(r > mid) add(x * 2 + 1, mid + 1, R, l, r, w);
	upd(x);
}
inline int query(int x, int L, int R, int l, int r) {
	if(l <= L && R <= r) return sum1[x];
	push(x);
	int mid = (L + R) >> 1, ret = 0;
	if(l <= mid) ret += query(x * 2, L, mid, l, r);
	if(r > mid) ret += query(x * 2 + 1, mid + 1, R, l, r);
	return ret % mod;
}
void inc(int x, int L, int R, int p, int w) {
	if(L == R) return (sum1[x] += w) %= mod, (sum2[x] += (ll)w * arr[p] % mod) %= mod, void();
	push(x); int mid = (L + R) >> 1; p <= mid ? inc(x * 2, L, mid, p, w) : inc(x * 2 + 1, mid + 1, R, p, w); upd(x);
}
void build(int x, int L, int R) {
	tag[x] = 1;
	if(L == R) return sum1[x] = sum2[x] = (L == 1), void(); 
	int mid = (L + R) >> 1;
	build(x * 2, L, mid), build(x * 2 + 1, mid + 1, R), upd(x);
}
int pw[N];
int main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n;
	L(i, 1, n) {
		cin >> a[i];
	}
	L(i, 1, n) {
		cin >> b[i];
	}
	L(i, 1, n) {
		arr[++tot] = a[i];
		arr[++tot] = b[i];
	}
	sort(arr + 1, arr + tot + 1);
	tot = unique(arr + 1, arr + tot + 1) - arr - 1;
	L(i, 1, n) {
		a[i] = lower_bound(arr + 1, arr + tot + 1, a[i]) - arr;
		b[i] = lower_bound(arr + 1, arr + tot + 1, b[i]) - arr;
	}
	pw[0] = 1;
	L(i, 1, n) {
		pw[i] = (ll)pw[i - 1] * 2 % mod;
	}
	int ans = 0;
	L(tst, 0, 1) {
		build(1, 1, tot);
		L(i, 1, n) {
			if(a[i] > b[i])swap(a[i], b[i]);
			int d = query(1, 1, tot, 1, a[i]);
			add(1, 1, tot, 1, a[i], 0);
			inc(1, 1, tot, a[i], d);
			int s = query(1, 1, tot, 1, b[i]);
			inc(1, 1, tot, b[i], s);
			if(b[i] < tot) add(1, 1, tot, b[i] + 1, tot, 2);
			(ans += (ll) sum2[1] * pw[n - i] % mod) %= mod;
		}
		if(tst == 1) {
			(ans += mod - (ll) n * sum2[1] % mod) %= mod;
		}
		reverse(a + 1, a + n + 1);
		reverse(b + 1, b + n + 1);
	}
	L(i, 1, n) {
		(ans += mod - (ll) (arr[a[i]] + arr[b[i]]) * pw[n - 1] % mod) %= mod;
	}
	cout << ans << '\n';
	return 0;
} 

int main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n;
	L(i, 1, n) {
		cin >> a[i];
	}
	L(i, 1, n) {
		cin >> b[i];
	}
	L(i, 1, n) {
		arr[++tot] = a[i];
		arr[++tot] = b[i];
	}
	sort(arr + 1, arr + tot + 1);
	tot = unique(arr + 1, arr + tot + 1) - arr - 1;
	L(i, 1, n) {
		a[i] = lower_bound(arr + 1, arr + tot + 1, a[i]) - arr;
		b[i] = lower_bound(arr + 1, arr + tot + 1, b[i]) - arr;
	}
	pw[0] = 1;
	L(i, 1, n) {
		pw[i] = (ll)pw[i - 1] * 2 % mod;
	}
	int ans = 0;
	L(tst, 0, 1) {
		build(1, 1, tot);
		int mn = 1;
		L(i, 1, n) {
			if(a[i] > b[i])swap(a[i], b[i]);
			if(mn < a[i]) {
				int s = 0;
				L(j, mn, a[i] - 1) {
					int w = query(1, 1, tot, j, j);
					(s += w) %= mod;
					inc(1, 1, tot, j, (mod - w) % mod);
				}
				inc(1, 1, tot, a[i], s);
				mn = a[i];
			} else if(a[i] > 1) {
				int r = query(1, 1, tot, 1, a[i] - 1);
				assert(r == 0);
			}
			int s = query(1, 1, tot, 1, b[i]);
			inc(1, 1, tot, b[i], s);
			if(b[i] < tot) add(1, 1, tot, b[i] + 1, tot, 2);
			(ans += (ll) sum2[1] * pw[n - i] % mod) %= mod;
		}
		if(tst == 1) {
			(ans += mod - (ll) n * sum2[1] % mod) %= mod;
		}
		reverse(a + 1, a + n + 1);
		reverse(b + 1, b + n + 1);
	}
	L(i, 1, n) {
		(ans += mod - (ll) (arr[a[i]] + arr[b[i]]) * pw[n - 1] % mod) %= mod;
	}
	cout << ans << '\n';
	return 0;
} 

详细

answer.code:106:5: error: redefinition of ‘int main()’
  106 | int main() {
      |     ^~~~
answer.code:56:5: note: ‘int main()’ previously defined here
   56 | int main() {
      |     ^~~~