Submission #1799711


Source Code Expand

#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<list>
#include<functional>
#define mp make_pair
#define X first
#define Y second
#define INF 1987654321
#define PI 3.14159265358979323846264
#define MOD 1000000007LL
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef complex<double> base;
ll POW(ll a, ll b) { if (b == 0)return 1; if (b == 1)return a; if (b & 1)return (a*POW(a, b - 1)) % MOD; ll t = POW(a, b / 2); return (t*t) % MOD; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[] = { 0,-1,1,0 }, dy[] = { 1,0,0,-1 };//동북남서

int p[200001];
int Ltree[524288], Rtree[524288];
void update(int node, int S, int E, int i)
{
	if (S == E)
	{
		Ltree[node] = Rtree[node] = 1;
		return;
	}
	if (i <= (S + E) / 2) update(node * 2, S, (S + E) / 2, i);
	else update(node * 2 + 1, (S + E) / 2 + 1, E, i);
	Ltree[node] = Ltree[node * 2];
	if (Ltree[node] == (S + E) / 2 - S + 1)Ltree[node] += Ltree[node * 2 + 1];
	Rtree[node] = Rtree[node * 2 + 1];
	if (Rtree[node] == E-(S+E)/2)Rtree[node] += Rtree[node * 2];
}
int Lfind(int node, int S, int E, int i, int j)
{
	if (i > E || j < S)return 0;
	if (i <= S && j >= E)return Ltree[node];
	return Lfind(node * 2, S, (S + E) / 2, i, j) + Lfind(node * 2 + 1, (S + E) / 2 + 1, E, i, j);
}
int Rfind(int node, int S, int E, int i, int j)
{
	if (i > E || j < S)return 0;
	if (i <= S && j >= E)return Rtree[node];
	return Rfind(node * 2, S, (S + E) / 2, i, j) + Rfind(node * 2 + 1, (S + E) / 2 + 1, E, i, j);
}
int main() {
	int n;
	scanf("%d", &n);
	fup(i, 1, n, 1)
	{
		int x;
		scanf("%d", &x);
		p[x] = i;
	}
	ll ans = 0;
	fdn(i, n, 1, 1)
	{
		int t = p[i];
		update(1, 1, n, t);
		ans += 1LL * i*Lfind(1, 1, n, t, n)*Rfind(1, 1, n, 1, t);
	}
	printf("%lld", ans);
}

Submission Info

Submission Time
Task B - Minimum Sum
User cheetose
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2511 Byte
Status WA
Exec Time 121 ms
Memory 5120 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:75:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:79:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &x);
                  ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 8
WA × 5
Set Name Test Cases
Sample example0, example1, example2
All corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2
Case Name Status Exec Time Memory
corner0 AC 93 ms 5120 KB
corner1 AC 91 ms 5120 KB
corner2 AC 2 ms 2304 KB
corner3 AC 95 ms 5120 KB
example0 AC 2 ms 2304 KB
example1 AC 2 ms 2304 KB
example2 AC 2 ms 2304 KB
maxrand0 WA 121 ms 5120 KB
maxrand1 WA 121 ms 5120 KB
maxrand2 WA 121 ms 5120 KB
rand0 WA 2 ms 2304 KB
rand1 AC 2 ms 2304 KB
rand2 WA 2 ms 2304 KB