Submission #27836105


Source Code Expand

#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;
vector<pair<int, int>>t;
#define int long long
int dp[61][2];
int val[61][2];
int arr[61];
vector<int>b;
int treeN;
int tree[1 << 22];
int quarry(int l, int r, int L, int R, int idx)
{
	if (l <= L && R <= r)
	{
		return tree[idx];
	}
	if (L > r || R < l)
	{
		return 0;
	}
	return quarry(l, r, L, (L + R) / 2, idx * 2) + quarry(l, r, (L + R) / 2 + 1, R, idx * 2 + 1);
}
void update(int idx, int changevalue)
{
	idx += treeN;
	tree[idx] += changevalue;
	while (idx != 1)
	{
		idx /= 2;
		tree[idx] = tree[idx * 2] + tree[idx * 2 + 1];
	}
}
map<int, int>aa;
map<int, int>bb;
signed main()
{
	int N;
	cin >> N;
	for (treeN=1; treeN < N; treeN *= 2);
	int i;
	int ans = 0;
	for (i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		t.push_back({ a,0 });
	}
	for (i = 0; i < N; i++)
	{
		cin >> t[i].second;
		b.push_back(t[i].second);
	}
	sort(t.begin(), t.end());
	sort(b.begin(), b.end());
	
	for (i = 0; i < N;)
	{
		int o = t[i].first;
		int j;
		for (j = i; j < N; j++)
		{
			if (t[j].first != o)
				break;
			int p = lower_bound(b.begin(), b.end(), t[j].second) - b.begin();
			update(p, 1);
		}
		for (j = i; j < N; j++)
		{
			if (t[j].first != o)
				break;
			int p = lower_bound(b.begin(), b.end(), t[j].second) - b.begin();
			ans += quarry(p, N - 1, 0, treeN - 1, 1);
		}
		i = j;
		
	}
	cout << ans;
}

Submission Info

Submission Time
Task F - Jealous Two
User codingmorning
Language C++ (GCC 9.2.1)
Score 500
Code Size 1499 Byte
Status AC
Exec Time 242 ms
Memory 9476 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 24
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.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, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 13 ms 3520 KiB
random_01.txt AC 239 ms 9476 KiB
random_02.txt AC 117 ms 6220 KiB
random_03.txt AC 239 ms 9344 KiB
random_04.txt AC 192 ms 8264 KiB
random_05.txt AC 235 ms 9468 KiB
random_06.txt AC 75 ms 5228 KiB
random_07.txt AC 171 ms 7720 KiB
random_08.txt AC 127 ms 6500 KiB
random_09.txt AC 172 ms 7904 KiB
random_10.txt AC 59 ms 4496 KiB
random_11.txt AC 107 ms 5432 KiB
random_12.txt AC 114 ms 5796 KiB
random_13.txt AC 242 ms 9472 KiB
random_14.txt AC 181 ms 7996 KiB
random_15.txt AC 199 ms 8264 KiB
random_16.txt AC 56 ms 4428 KiB
random_17.txt AC 132 ms 7908 KiB
random_18.txt AC 162 ms 7968 KiB
random_19.txt AC 151 ms 9444 KiB
random_20.txt AC 149 ms 9412 KiB
sample_01.txt AC 3 ms 3632 KiB
sample_02.txt AC 2 ms 3548 KiB
sample_03.txt AC 3 ms 3460 KiB