Submission #18876226


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int H,W,N;
int Y[202020],X[202020];
vector<int> R[202020],C[202020];

template<class V, int ME> class BIT {
public:
	V bit[1<<ME],val[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { val[e++]+=v; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
	void set(int e,V v) { add(e,v-val[e]);}
	int lower_bound(V val) {
		V tv=0; int i,ent=0;
		for(i=ME-1;i>=0;i--) if(tv+bit[ent+(1<<i)-1]<val) tv+=bit[ent+(1<<i)-1],ent+=(1<<i);
		return ent;
	}
};
BIT<int,20> bt;
int did[202020];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>N;
	FOR(i,N) {
		cin>>Y[i]>>X[i];
		Y[i]--,
		X[i]--;
		R[Y[i]].push_back(X[i]);
		C[X[i]].push_back(Y[i]);
	}
	FOR(i,200001) R[i].push_back(W), sort(ALL(R[i]));
	FOR(i,200001) sort(ALL(C[i]));
	ll ok=R[0][0];
	
	FOR(x,R[0][0]) bt.add(x,1), did[x]=1;
	
	int a=1;
	for(y=1;y<H;y++) {
		
		if(R[y][0]==0) a=0;
		
		FORR(x,R[y]) {
			if(did[x]==1) {
				did[x]=0;
				bt.add(x,-1);
			}
		}
		if(a==1) {
			ok+=R[y][0]+bt(W)-bt(R[y][0]);
		}
		else {
			ok+=bt(W);
		}
	}
	
	
	
	cout<<ok<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Submission Info

Submission Time
Task F - Rook on Grid
User kmjp
Language C++ (GCC 9.2.1)
Score 600
Code Size 1975 Byte
Status AC
Exec Time 158 ms
Memory 27344 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:37:8: warning: unused variable ‘j’ [-Wunused-variable]
   37 |  int i,j,k,l,r,x,y; string s;
      |        ^
./Main.cpp:37:10: warning: unused variable ‘k’ [-Wunused-variable]
   37 |  int i,j,k,l,r,x,y; string s;
      |          ^
./Main.cpp:37:12: warning: unused variable ‘l’ [-Wunused-variable]
   37 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp:37:14: warning: unused variable ‘r’ [-Wunused-variable]
   37 |  int i,j,k,l,r,x,y; string s;
      |              ^
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:6:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
./Main.cpp:81:38: note: in expansion of macro ‘FOR’
   81 |  FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                      ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 29
Set Name Test Cases
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
Case Name Status Exec Time Memory
hand_01.txt AC 41 ms 21556 KB
hand_02.txt AC 34 ms 21688 KB
hand_03.txt AC 25 ms 19276 KB
hand_04.txt AC 38 ms 19392 KB
hand_05.txt AC 33 ms 19424 KB
hand_06.txt AC 36 ms 19348 KB
random_01.txt AC 158 ms 27344 KB
random_02.txt AC 145 ms 25012 KB
random_03.txt AC 143 ms 25112 KB
random_04.txt AC 156 ms 27300 KB
random_05.txt AC 152 ms 27208 KB
random_06.txt AC 140 ms 25936 KB
random_07.txt AC 144 ms 25656 KB
random_08.txt AC 41 ms 21640 KB
random_09.txt AC 32 ms 21680 KB
random_10.txt AC 34 ms 21728 KB
random_11.txt AC 68 ms 22816 KB
random_12.txt AC 69 ms 22760 KB
random_13.txt AC 71 ms 22780 KB
random_14.txt AC 66 ms 22800 KB
random_15.txt AC 70 ms 22688 KB
random_16.txt AC 73 ms 22760 KB
random_17.txt AC 68 ms 22800 KB
random_18.txt AC 30 ms 19268 KB
random_19.txt AC 35 ms 19460 KB
random_20.txt AC 28 ms 19316 KB
sample_01.txt AC 31 ms 19428 KB
sample_02.txt AC 31 ms 19356 KB
sample_03.txt AC 40 ms 21656 KB