QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#365250#8050. Random PermutationDodo Kindergarten (Zhikun Wang, Yeyuan Chen, Dong Yang)WA 1724ms5592kbC++141.5kb2024-03-24 22:48:272024-03-24 22:48:28

Judging History

This is the latest submission verdict.

  • [2024-03-24 22:48:28]
  • Judged
  • Verdict: WA
  • Time: 1724ms
  • Memory: 5592kb
  • [2024-03-24 22:48:27]
  • Submitted

answer


#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
    read(first);
    read(args...);
}

int n, p[300030];

int pool1[1000030], pool3[1000030];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	cin>>n;

	for(int i=1;i<=n;i++) {
		cin>>p[i];
	}

	int *cc1 = pool1 + 500000, *cc2 = pool3 + 500000;

	ll ans = 0;
	for(int i=1;i<=n;i++) {
		double balance = abs(1.0* (p[i] - (n+1)/2.0) / n);
		int lim = max(200, int(5.0/(1e-9+balance*balance)));
		// int lim = 300;
		lim = min(lim, max(i, n-i) + 10);
		int cnt = 0;
		for(int j=i;j>=max(1, i-lim);j--) {
			if(p[j] < p[i]) cnt -= 1;
			else cnt += 1;
			int *cc = j%2==0 ? cc2 : cc1;
			cc[cnt] += 1;
		}
		cnt = 0;
		for(int j=i; j<=min(n, i+lim);j++) {
			int *c1 = cc1, *c2 = cc2;
			if(j%2 == 0) {
				swap(c1, c2);
			}
			ans += 1ll*c1[cnt+1] * p[i];
			ans += 1ll*c2[cnt+2] * p[i];
			if(p[j+1] < p[i]) cnt += 1;
			else cnt -= 1;
		}
		memset(cc1-lim-10, 0, sizeof(int) * (2*lim+21));
		memset(cc2-lim-10, 0, sizeof(int) * (2*lim+21));
	}
	cout<<ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3668kb

input:

4
1 4 2 3

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: -100
Wrong Answer
time: 1724ms
memory: 5592kb

input:

100000
56449 21738 74917 44834 36187 96576 37204 28451 3444 13029 66039 8955 51445 30706 27229 37159 66052 16691 70389 29935 44984 3648 75082 73600 76621 28345 5298 37940 49412 85260 92029 18185 84398 10233 79227 98312 96649 30680 65206 38879 75397 26951 11294 58085 37297 97167 59252 44104 4058 3796...

output:

246706402884249

result:

wrong answer 1st numbers differ - expected: '250202478701074', found: '246706402884249'