QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#663135#9477. Topological SortrageOfThunder#WA 0ms3756kbC++231.5kb2024-10-21 13:36:122024-10-21 13:36:12

Judging History

你现在查看的是最新测评结果

  • [2024-10-21 13:36:12]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3756kb
  • [2024-10-21 13:36:12]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "\33[32m[" << __LINE__ << "]\33[m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T& x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T& x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = - f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
const int N = 2e5 + 10, MOD = 998244353;
inline int power(int x, ll y = MOD - 2) {
	int ans = 1;
	for (; y; x = (ll) x * x % MOD, y >>= 1)
		if (y & 1) ans = (ll) ans * x % MOD;
	return ans;
}
int n, a[N], t[N];
void add(int x) {
	for (; x <= n; x += x & -x) t[x]++;
}
int query(int x) {
	int s = 0;
	for (; x; x ^= x & -x) s += t[x];
	return s;
}
signed main() {
	read(n);
	F(i, 1, n) {
		read(a[i]);
	}
	ll s = 0;
	stack <int> t;
	DF(i, n, 1) {
		s += n - i;
		while (t.size() && t.top() < a[i]) {
			s--;
			t.pop();
		}
		t.push(a[i]);
		// if (query(a[i])) s += n - i - 1;
		// else s += n - i;
		// s += max(0, query(a[i]) - 1);
		// add(a[i]);
	}
	cout << power(2, s);
	return 0;
}
/* why?
*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

input:

3
1 3 2

output:

4

result:

ok "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

5
1 2 3 4 5

output:

1024

result:

ok "1024"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

6
4 2 1 5 6 3

output:

4096

result:

ok "4096"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3756kb

input:

492
397 486 227 395 58 452 172 216 130 181 268 482 85 209 365 104 373 90 260 326 252 96 267 106 102 398 441 41 292 314 12 78 242 353 153 424 179 86 299 228 54 390 73 465 396 349 4 10 451 99 342 250 391 6 323 197 159 47 136 473 392 77 125 362 418 255 291 13 238 339 8 28 413 121 384 157 152 23 221 305...

output:

390557336

result:

wrong answer 1st words differ - expected: '73428942', found: '390557336'