提出 #18906388
ソースコード 拡げる
//Author: RingweEH
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define db double
using namespace std;
int min( int a,int b ) { return a<b ? a : b; }
int max( int a,int b ) { return a>b ? a : b; }
int read()
{
int x=0,w=1; char ch=getchar();
while ( ch>'9' || ch<'0' ) { if ( ch=='-' ) w=-1; ch=getchar(); }
while ( ch<='9' && ch>='0' ) x=x*10+ch-'0',ch=getchar();
return x*w;
}
#define lowbit(x) ((x)&(-x))
const int N=2e5+10;
int n,m,q,mfir[N];
pair<int,int> p[N*3];
bool vis[N];
struct BIT
{
int tr[N];
BIT() { memset( tr,0,sizeof(tr) ); }
void add( int x ) { for ( ; x<=m; x+=lowbit(x) ) tr[x]+=1; }
int sum( int x ) { int res=0; for ( ; x; x-=lowbit(x) ) res+=tr[x]; return res; }
}Tr;
int main()
{
n=read(); m=read(); q=read();
int limx=n+1,limy=m+1;
for ( int i=1; i<=q; i++ )
{
int x=read(),y=read();
p[i].first=x; p[i].second=y;
if ( x==1 ) limy=min( limy,y );
if ( y==1 ) limx=min( limx,x );
}
for ( int i=limx+1; i<=n; i++ )
q++,p[q].first=i,p[q].second=1;
for ( int i=limy+1; i<=m; i++ )
q++,p[q].first=1,p[q].second=i;
sort( p+1,p+1+q );
q=unique( p+1,p+1+q )-p-1;
int las=1; ll ans=0;
for ( int i=1; i<=q; i++ )
{
if ( vis[p[i].second]==0 ) { vis[p[i].second]=1; Tr.add(p[i].second); }
if ( i==q || p[i+1].first!=p[i].first )
{
ans+=Tr.sum(m)-Tr.sum(p[las].second-1); las=i+1;
}
}
printf( "%lld\n",1ll*n*m-ans );
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | F - Rook on Grid |
| ユーザ | RingweEH |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 600 |
| コード長 | 1593 Byte |
| 結果 | AC |
| 実行時間 | 64 ms |
| メモリ | 7068 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 600 / 600 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| 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 | 6 ms | 2276 KiB |
| hand_02.txt | AC | 1 ms | 2320 KiB |
| hand_03.txt | AC | 13 ms | 4024 KiB |
| hand_04.txt | AC | 10 ms | 3884 KiB |
| hand_05.txt | AC | 1 ms | 2304 KiB |
| hand_06.txt | AC | 1 ms | 2276 KiB |
| random_01.txt | AC | 44 ms | 4052 KiB |
| random_02.txt | AC | 64 ms | 7068 KiB |
| random_03.txt | AC | 53 ms | 5500 KiB |
| random_04.txt | AC | 44 ms | 4104 KiB |
| random_05.txt | AC | 56 ms | 5416 KiB |
| random_06.txt | AC | 49 ms | 4916 KiB |
| random_07.txt | AC | 49 ms | 5120 KiB |
| random_08.txt | AC | 2 ms | 2452 KiB |
| random_09.txt | AC | 2 ms | 2568 KiB |
| random_10.txt | AC | 2 ms | 2512 KiB |
| random_11.txt | AC | 37 ms | 3876 KiB |
| random_12.txt | AC | 33 ms | 3880 KiB |
| random_13.txt | AC | 34 ms | 3952 KiB |
| random_14.txt | AC | 33 ms | 3828 KiB |
| random_15.txt | AC | 34 ms | 3904 KiB |
| random_16.txt | AC | 34 ms | 3944 KiB |
| random_17.txt | AC | 34 ms | 3948 KiB |
| random_18.txt | AC | 3 ms | 2284 KiB |
| random_19.txt | AC | 3 ms | 2296 KiB |
| random_20.txt | AC | 1 ms | 2376 KiB |
| sample_01.txt | AC | 2 ms | 2252 KiB |
| sample_02.txt | AC | 1 ms | 2352 KiB |
| sample_03.txt | AC | 2 ms | 2252 KiB |