Submission #443614

# Submission time Handle Problem Language Result Execution time Memory
443614 2021-07-11T04:08:49 Z minhcool Examination (JOI19_examination) C++17
0 / 100
3000 ms 633712 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
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 {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int n, q;
vector<pair<int, ii>> students;
vector<pair<iii, int>> queries;

int answer[N];
int cnt;
int IT[N * 20 * 10];
gp_hash_table<int, int, hash> index;

int cal(int x1, int y1, int x2, int y2){
    int temp = (((x1 << 20) | y1) << 20) | ((x2 << 20) | y2);
	if(index.find(temp) != index.end()) return index[temp];
	cnt++;
	return index[temp] = cnt;
	return 1;
}

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 << 20), posy, val);
	if(lx == rx) return;
	int mid = (lx + rx) >> 1;
	if(posx <= mid) updx(cal(lx, mid, 1, 1LL << 20), lx, mid, posx, posy, val);
	else updx(cal(mid + 1, rx, 1, 1LL << 20), 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 << 20, 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;
	n = q = 1e5;
	for(int i = 1; i <= n; i++){
		int S, T;
		//cin >> S >> T;
		S = rand() % 15000 + 1, T = rand() % 15000 + 1;
		students.pb({S + T, {S, T}});
	}
	for(int i = 1; i <= q; i++){
		int a, b, c;
		//cin >> a >> b >> c;
		a = rand() % 15000 + 1, b = rand() % 15000 + 1, c = rand() % 15000 + 1;
		queries.pb({{{c, a}, b}, i});
	}
	sort(students.begin(), students.end());
	sort(queries.begin(), queries.end());
	reverse(queries.begin(), queries.end());
	cal(1, 1LL << 20, 1, 1LL << 20);
	//return;
	for(auto it : queries){
		while(students.size() && it.fi.fi.fi <= students.back().fi){
			updx(1, 1, 1LL << 20, students.back().se.fi, students.back().se.se, 1);
			students.pop_back();
		}
		//cout << students.size() << "\n";
		answer[it.se] = getx(1, 1LL << 20, it.fi.fi.se, 1LL << 20, it.fi.se, 1LL << 20);
	}
	//for(int i = 1; i <= q; i++) cout << answer[i] << "\n";
}

signed main(){
	ios_base::sync_with_stdio(0);
	//freopen("examination_19.inp", "r", stdin);
	//freopen("examination_19.out", "w", stdout);
	srand(time(NULL));
	process();
}
# Verdict Execution time Memory Grader output
1 Execution timed out 3097 ms 633404 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3087 ms 633712 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3087 ms 633712 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3097 ms 633404 KB Time limit exceeded
2 Halted 0 ms 0 KB -