提出 #18905167


ソースコード 拡げる

/*input
5 4 4
3 2
3 4
4 2
5 2


*/


// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}

const ll N = 2e5+5;
vi bit(N,0);
void add(ll idx,ll val)
{
	for(ll i = idx+1;i<N;i+=i&-i) bit[i]+=val;
}

ll prefixSum(ll idx)
{
	ll sum=0;
	for(ll i = idx+1;i>0;i-=i&-i) sum+=bit[i];
	return sum;
}

int solve()
{
	ll h,w,m,ans=0;
	cin>>h>>w>>m;
	vector<ll> row(h,w),col(w,h);
	rep(i,0,m)
	{
		ll x,y;cin>>x>>y;
		x--,y--;
		row[x] = min(row[x],y);
		col[y] = min(col[y],x);
	}


	/* 
		0 0 0 0 1 5
		0 0 1 0 0 3
		0 1 0 0 0 2
		0 0 0 0 0 6
		0 0 0 1 0 4
		1 0 0 0 0 
		0 1 0 0 0
 	*/
	rep(i,0,col[0]) ans+=row[i];

	vpii b;
	rep(j,0,row[0]) b.pb(mp(col[j],j));
	sort(b.begin(), b.end());

	ll L = 0;
	ll cnt=0;
	rep(i,0,sz(b))
	{
		pii p = b[i];
		while(L<p.F && L<col[0]) 
		{
			add(row[L],1);
			cnt++;
			L++;
		}

		ans+=col[p.S] - ( cnt - prefixSum(p.S-1));
	}

	cout<<ans<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

提出情報

提出日時
問題 F - Rook on Grid
ユーザ umangjain5000
言語 C++ (GCC 9.2.1)
得点 600
コード長 3294 Byte
結果 AC
実行時間 69 ms
メモリ 12116 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 29
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.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
ケース名 結果 実行時間 メモリ
hand_01.txt AC 30 ms 12060 KiB
hand_02.txt AC 26 ms 12068 KiB
hand_03.txt AC 5 ms 6404 KiB
hand_04.txt AC 7 ms 6264 KiB
hand_05.txt AC 6 ms 4624 KiB
hand_06.txt AC 4 ms 4624 KiB
random_01.txt AC 68 ms 12052 KiB
random_02.txt AC 45 ms 8292 KiB
random_03.txt AC 53 ms 8460 KiB
random_04.txt AC 69 ms 12068 KiB
random_05.txt AC 68 ms 12116 KiB
random_06.txt AC 58 ms 9976 KiB
random_07.txt AC 56 ms 8940 KiB
random_08.txt AC 25 ms 12112 KiB
random_09.txt AC 34 ms 12048 KiB
random_10.txt AC 26 ms 12064 KiB
random_11.txt AC 28 ms 4560 KiB
random_12.txt AC 32 ms 4544 KiB
random_13.txt AC 27 ms 4608 KiB
random_14.txt AC 35 ms 4484 KiB
random_15.txt AC 32 ms 4564 KiB
random_16.txt AC 33 ms 4448 KiB
random_17.txt AC 28 ms 4648 KiB
random_18.txt AC 5 ms 4596 KiB
random_19.txt AC 3 ms 4596 KiB
random_20.txt AC 4 ms 4560 KiB
sample_01.txt AC 4 ms 4604 KiB
sample_02.txt AC 4 ms 4512 KiB
sample_03.txt AC 27 ms 12064 KiB