Submission #15803665


Source Code Expand

Copy
#include <bits/stdc++.h>
typedef long long LL;
const int MAXN = 1 << 18 | 1, MOD = 1e9 + 7;
inline int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }
inline int sub(int x, int y) { return x < y ? x - y + MOD : x - y; }
inline int mul(int x, int y) { return 1LL * x * y - 1LL * x * y / MOD * MOD; }
inline int Qpow(int a, int b) { int ans = 1; for (; b; a = mul(a, a), b >>= 1) if (b & 1) ans = mul(ans, a); return ans; }
int n, l, h, ans;
int p[MAXN], val[MAXN];
template <int N, int S>
struct Trie {
int QAQ[N];
inline void insert(int x, int val) { for (; x > 1; x >>= 1) val = mul(val, x), QAQ[x] = add(QAQ[x], val); }
inline int query(int x) {
int ans = 0, pro = 1;
for (; x > 1; x >>= 1) pro = mul(pro, x), ans = add(ans, mul(mul(QAQ[x ^ 1], pro), x >> 1));
return ans;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>

typedef long long LL;

const int MAXN = 1 << 18 | 1, MOD = 1e9 + 7;
inline int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }
inline int sub(int x, int y) { return x < y ? x - y + MOD : x - y; }
inline int mul(int x, int y) { return 1LL * x * y - 1LL * x * y / MOD * MOD; }
inline int Qpow(int a, int b) { int ans = 1; for (; b; a = mul(a, a), b >>= 1) if (b & 1) ans = mul(ans, a); return ans; }

int n, l, h, ans;
int p[MAXN], val[MAXN];

template <int N, int S>
struct Trie {
	int QAQ[N];
	inline void insert(int x, int val) { for (; x > 1; x >>= 1) val = mul(val, x), QAQ[x] = add(QAQ[x], val); }
	inline int query(int x) {
		int ans = 0, pro = 1;
		for (; x > 1; x >>= 1) pro = mul(pro, x), ans = add(ans, mul(mul(QAQ[x ^ 1], pro), x >> 1));
		return ans;
	}
};
Trie <MAXN, 2> T;

void gao(int x, int L, int R) {
	if (L < R) {
		int mid = (L + R) >> 1;
		gao(x << 1, L, mid), gao(x << 1 | 1, mid + 1, R);
		for (int i = L; i <= mid; ++i) T.insert(p[i] + l - 1, val[i]);
		for (int i = mid + 1; i <= R; ++i) ans = add(ans, mul(mul(x, val[i]), T.query(p[i] + l - 1)));
		for (int i = L; i <= mid; ++i) T.insert(p[i] + l - 1, MOD - val[i]);
	}
	for (int i = L; i <= R; ++i) val[i] = mul(val[i], x);
}

int main() {
	scanf("%d", &h), n = (1 << h) - 1, l = 1 << (h - 1);
	for (int i = 1; i <= l; ++i) scanf("%d", p + i);
	for (int i = 1; i <= l; ++i) val[i] = 1;
	gao(1, 1, l);
	printf("%d\n", ans);
	return 0;
}

Submission Info

Submission Time
Task D - Twin Binary Trees
User realSpongeBob
Language C++ (GCC 9.2.1)
Score 1000
Code Size 1499 Byte
Status AC
Exec Time 279 ms
Memory 5832 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:38:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   38 |  scanf("%d", &h), n = (1 << h) - 1, l = 1 << (h - 1);
      |  ~~~~~^~~~~~~~~~
./Main.cpp:39:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   39 |  for (int i = 1; i <= l; ++i) scanf("%d", p + i);
      |                               ~~~~~^~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 3
AC × 22
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
001.txt AC 6 ms 3676 KB
002.txt AC 2 ms 3684 KB
003.txt AC 4 ms 3736 KB
004.txt AC 15 ms 3792 KB
005.txt AC 64 ms 4192 KB
006.txt AC 131 ms 4708 KB
007.txt AC 276 ms 5720 KB
008.txt AC 270 ms 5752 KB
009.txt AC 272 ms 5656 KB
010.txt AC 268 ms 5760 KB
011.txt AC 274 ms 5664 KB
012.txt AC 269 ms 5664 KB
013.txt AC 272 ms 5724 KB
014.txt AC 273 ms 5656 KB
015.txt AC 272 ms 5752 KB
016.txt AC 273 ms 5756 KB
017.txt AC 277 ms 5624 KB
018.txt AC 276 ms 5832 KB
019.txt AC 279 ms 5756 KB
s1.txt AC 2 ms 3680 KB
s2.txt AC 3 ms 3708 KB
s3.txt AC 2 ms 3792 KB


2025-04-02 (Wed)
22:10:02 +00:00