Submission #36249590


Source Code Expand

#include<bits/stdc++.h>

using namespace std;

namespace acah
{
	constexpr int maxn = 2e5 + 7;
	constexpr int p = 998244353;
	constexpr int H = 2e5;
	
	int N, A[maxn], cc[maxn], cs[maxn], s, S;
	
	inline void add(int &a, int b) {a += b, a -= (a >= p ? p : 0);}
	
	inline int lbt(int x) {return x & (-x);}
	inline void upd(int p, int x) {for(; p <= H; p += lbt(p)) ++cc[p], add(cs[p], x);}
	inline int qryc(int p) {int s = 0; for(; p; p -= lbt(p)) s += cc[p]; return s;}
	inline int qrys(int p) {int s = 0; for(; p; p -= lbt(p)) add(s, cs[p]); return s;}
	
	inline int inv(int a)
	{
		for(int t = a, x = p - 3; x; t = 1ll * t * t % p, x >>= 1)
			if(x & 1) a = 1ll * a * t % p;
		return a;
	}
	
	int work()
	{
		ios::sync_with_stdio(false), cin.tie(nullptr);
		
		cin >> N; for(int i = 1; i <= N; i++) cin >> A[i];
		for(int i = 1; i <= N; i++) {
			add(S, A[i]), upd(A[i], A[i]);
			add(s, 2ll * A[i] * (qryc(A[i]) - 1) % p);
			add(s, A[i]);
			add(s, 2ll * (S + p - qrys(A[i])) % p);
			cout << 1ll * s * inv(1ll * i * i % p) % p << '\n';
		}
		
		return 0;
	}
}

int main() {return acah::work();}

Submission Info

Submission Time
Task F - Double Chance
User whhsteven
Language C++ (GCC 9.2.1)
Score 500
Code Size 1142 Byte
Status AC
Exec Time 78 ms
Memory 6000 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 30
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 6 ms 3616 KiB
example_01.txt AC 3 ms 3652 KiB
hand_00.txt AC 71 ms 4320 KiB
hand_01.txt AC 61 ms 4332 KiB
hand_02.txt AC 68 ms 5828 KiB
hand_03.txt AC 70 ms 5880 KiB
hand_04.txt AC 6 ms 3724 KiB
hand_05.txt AC 3 ms 3536 KiB
hand_06.txt AC 2 ms 3596 KiB
hand_07.txt AC 3 ms 3604 KiB
random_00.txt AC 78 ms 5820 KiB
random_01.txt AC 72 ms 5944 KiB
random_02.txt AC 74 ms 5876 KiB
random_03.txt AC 74 ms 5876 KiB
random_04.txt AC 72 ms 5888 KiB
random_05.txt AC 75 ms 5928 KiB
random_06.txt AC 75 ms 5924 KiB
random_07.txt AC 75 ms 6000 KiB
random_08.txt AC 74 ms 5892 KiB
random_09.txt AC 74 ms 5920 KiB
random_10.txt AC 73 ms 5924 KiB
random_11.txt AC 75 ms 5956 KiB
random_12.txt AC 74 ms 5896 KiB
random_13.txt AC 75 ms 5952 KiB
random_14.txt AC 73 ms 5896 KiB
random_15.txt AC 73 ms 5892 KiB
random_16.txt AC 74 ms 5824 KiB
random_17.txt AC 75 ms 5928 KiB
random_18.txt AC 75 ms 5892 KiB
random_19.txt AC 73 ms 5928 KiB