답안 #443606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
443606 2021-07-11T03:05:06 Z minhcool Examination (JOI19_examination) C++17
0 / 100
3000 ms 283024 KB
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define fi first
#define se second
#define pb push_back
#define hash hash1
#define index indexx
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 2e5 + 5;
 
const int oo = 1e18 + 7, mod = 1e9 + 7;
 
const int hashy = 1e9 + 87;
 
/*
I think this is one of the easiest problems that you can give a guy if he knows segtree 2D
*/
 
// I think this will run as slow as f*ck, but it is sure O(1) lol
 
struct hash{
	int operator()(const ii&a)const{
		return ((a.fi % hashy) << 30) | (a.se % hashy);
	}
};
 
int n, q;
vector<pair<int, ii>> students;
vector<pair<iii, int>> queries;
 
int answer[N];
int cnt;
int IT[N * 20 * 20];
map<iiii, int> index;
 
int cal(int x1, int y1, int x2, int y2){
	if(index.find({{x1, y1}, {x2, y2}}) != index.end()) return index[{{x1, y1}, {x2, y2}}];
	cnt++;
	return index[{{x1, y1}, {x2, y2}}] = cnt;
}
 
void updy(int ind, int lx, int rx, int ly, int ry, int posy, int val){
	//cout << ind << " " << lx << " " << rx << " " << ly << " " << ry << "\n";
	IT[ind] += val;
	if(ly == ry) return;
	int mid = (ly + ry) >> 1;
	if(posy <= mid) updy(cal(lx, rx, ly, mid), lx, rx, ly, mid, posy, val);
	else updy(cal(lx, rx, mid + 1, ry), lx, rx, mid + 1, ry, posy, val);
}
 
void updx(int ind, int lx, int rx, int posx, int posy, int val){
	updy(ind, lx, rx, 1, (1LL << 30), posy, val);
	if(lx == rx) return;
	int mid = (lx + rx) >> 1;
	if(posx <= mid) updx(cal(lx, mid, 1, 1LL << 30), lx, mid, posx, posy, val);
	else updx(cal(mid + 1, rx, 1, 1LL << 30), mid + 1, rx, posx, posy, val);
	//int temp2 = cal(((long long)(mid + 1) << 30LL) + rx, 1LL << 31);
}
 
int gety(int lx, int rx, int ly, int ry, int Ly, int Ry){
	if(ly > Ry || ry < Ly) return 0;
	if(ly >= Ly && ry <= Ry){
		//cout << cal(((long long)lx << 20LL) + rx, ((long long)ly << 20LL) + ry) << " " << lx << " " << ly << " " << rx << " " << ry << " " << IT[cal(((long long)lx << 20LL) + rx, ((long long)ly << 20LL) + ry)] << "\n";
		//if(IT[cal(lx, rx, ly, ry)]) cout << lx << " " << rx << " " << ly << " " << ry << " " << Ly << " " << Ry << "\n";
		return IT[cal(lx, rx, ly, ry)];
	}
	int mid = (ly + ry) >> 1;
	return gety(lx, rx, ly, mid, Ly, Ry) + gety(lx, rx, mid + 1, ry, Ly, Ry);
}
 
int getx(int lx, int rx, int Lx, int Rx, int Ly, int Ry){
	if(lx > Rx || rx < Lx) return 0;
	if(lx >= Lx && rx <= Rx){
		//cout << lx << " " << rx << "\n";
		return gety(lx, rx, 1, 1LL << 30, Ly, Ry);
	}
	int mid = (lx + rx) >> 1;
	return getx(lx, mid, Lx, Rx, Ly, Ry) + getx(mid + 1, rx, Lx, Rx, Ly, Ry);
}
 
void process(){
	cin >> n >> q;
	for(int i = 1; i <= n; i++){
		int S, T;
		cin >> S >> T;
		students.pb({S + T, {S, T}});
	}
	for(int i = 1; i <= q; i++){
		int a, b, c;
		cin >> a >> b >> c;
		queries.pb({{{c, a}, b}, i});
	}
	sort(students.begin(), students.end());
	sort(queries.begin(), queries.end());
	reverse(queries.begin(), queries.end());
	cal(1, 1LL << 30, 1, 1LL << 30);
	//return;
	for(auto it : queries){
		while(students.size() && it.fi.fi.fi <= students.back().fi){
			updx(1, 1, 1LL << 30, students.back().se.fi, students.back().se.se, 1);
			students.pop_back();
		}
		//cout << students.size() << "\n";
		answer[it.se] = getx(1, 1LL << 30, it.fi.fi.se, 1LL << 30, it.fi.se, 1LL << 30);
	}
	for(int i = 1; i <= q; i++) cout << answer[i] << "\n";
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	process();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 716 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 4 ms 672 KB Output is correct
4 Correct 4 ms 1224 KB Output is correct
5 Correct 4 ms 1228 KB Output is correct
6 Correct 5 ms 1356 KB Output is correct
7 Correct 1567 ms 282596 KB Output is correct
8 Correct 1538 ms 282628 KB Output is correct
9 Correct 1542 ms 283024 KB Output is correct
10 Incorrect 1302 ms 217628 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3065 ms 219868 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3065 ms 219868 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 716 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 4 ms 672 KB Output is correct
4 Correct 4 ms 1224 KB Output is correct
5 Correct 4 ms 1228 KB Output is correct
6 Correct 5 ms 1356 KB Output is correct
7 Correct 1567 ms 282596 KB Output is correct
8 Correct 1538 ms 282628 KB Output is correct
9 Correct 1542 ms 283024 KB Output is correct
10 Incorrect 1302 ms 217628 KB Output isn't correct
11 Halted 0 ms 0 KB -