結果

問題 No.961 Vibrant Fillumination
ユーザー chocoruskchocorusk
提出日時 2019-12-24 02:14:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,633 bytes
コンパイル時間 1,443 ms
コンパイル使用メモリ 130,444 KB
実行使用メモリ 814,580 KB
最終ジャッジ日時 2023-10-24 00:05:36
合計ジャッジ時間 15,637 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
19,292 KB
testcase_01 AC 6 ms
19,292 KB
testcase_02 AC 217 ms
24,876 KB
testcase_03 AC 229 ms
25,084 KB
testcase_04 AC 221 ms
24,868 KB
testcase_05 AC 222 ms
24,884 KB
testcase_06 AC 225 ms
24,880 KB
testcase_07 AC 217 ms
24,876 KB
testcase_08 AC 215 ms
24,872 KB
testcase_09 AC 223 ms
24,892 KB
testcase_10 AC 138 ms
29,196 KB
testcase_11 AC 143 ms
29,528 KB
testcase_12 AC 140 ms
29,272 KB
testcase_13 AC 138 ms
29,112 KB
testcase_14 AC 146 ms
30,404 KB
testcase_15 AC 134 ms
28,452 KB
testcase_16 AC 143 ms
30,432 KB
testcase_17 AC 139 ms
28,672 KB
testcase_18 AC 133 ms
29,392 KB
testcase_19 AC 129 ms
29,040 KB
testcase_20 AC 136 ms
29,276 KB
testcase_21 AC 134 ms
28,776 KB
testcase_22 AC 130 ms
28,660 KB
testcase_23 AC 135 ms
28,272 KB
testcase_24 AC 132 ms
29,160 KB
testcase_25 AC 143 ms
29,532 KB
testcase_26 AC 97 ms
25,040 KB
testcase_27 AC 109 ms
28,836 KB
testcase_28 AC 101 ms
25,048 KB
testcase_29 AC 114 ms
29,100 KB
testcase_30 AC 90 ms
24,992 KB
testcase_31 AC 75 ms
23,848 KB
testcase_32 AC 95 ms
26,196 KB
testcase_33 AC 6 ms
19,288 KB
testcase_34 MLE -
testcase_35 MLE -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<P, ll> Pl;
template<typename T>
struct BIT{ //1-indexed
	using F=function<T(T, T)>;
	const F f;
    vector<T> bit;
    int size;
    BIT(int n, const F f):f(f), size(n), bit(n+1, 0){}
    T sum(int i){
        T s=0;
        while(i>0){
            s=f(s, bit[i]);
            i-=(i&(-i));
        }
        return s;
    }
    void add(int i, T x){
        while(i<=size){
            bit[i]=f(bit[i], x);
            i+=(i&(-i));
        }
    }
};
int n, Q;
ll h[50050];
vector<int> ind[50050];
int a[50050], b[50050], c[50050], d[50050], e[50050];
ll ans[50050];
int q[50050];
vector<int> vq[100010];
vector<int> vl[100010], vr[100010];
void calc(int e){
	BIT<int> bit(2*n, [](int a, int b){ return a+b;});
	for(auto k:ind[e]){
		vl[a[k]].push_back(k);
		vr[c[k]].push_back(k);
	}
	for(int i=0; i<2*n; i++){
		for(auto k:vl[i]){
			bit.add(b[k]+1, 1);
			bit.add(d[k]+1, -1);
		}
		for(auto k:vr[i]){
			bit.add(b[k]+1, -1);
			bit.add(d[k]+1, 1);
		}
		for(auto k:vq[i]){
			if(bit.sum(q[k]+1)>0) ans[k]^=h[e];
		}
		vl[i].clear(); vr[i].clear();
	}
}
int sum[500][500];
vector<Pl> vl2[100010], vr2[100010];
void calc2(int e){
	if(ind[e].empty()) return;
	vector<int> vx(2*ind[e].size()), vy(2*ind[e].size());
	int j=0;
	for(int j=0; j<ind[e].size(); j++){
		int k=ind[e][j];
		vx[2*j]=a[k], vx[2*j+1]=c[k], vy[2*j]=b[k], vy[2*j+1]=d[k];
	}
	sort(vx.begin(), vx.end());
	vx.erase(unique(vx.begin(), vx.end()), vx.end());
	sort(vy.begin(), vy.end());
	vy.erase(unique(vy.begin(), vy.end()), vy.end());
	int nx=vx.size(), ny=vy.size();
	for(int i=0; i<nx; i++) fill(sum[i], sum[i]+ny, 0);
	for(auto k:ind[e]){
		int a1=lower_bound(vx.begin(), vx.end(), a[k])-vx.begin();
		int b1=lower_bound(vy.begin(), vy.end(), b[k])-vy.begin();
		int c1=lower_bound(vx.begin(), vx.end(), c[k])-vx.begin();
		int d1=lower_bound(vy.begin(), vy.end(), d[k])-vy.begin();
		sum[a1][b1]++;
		sum[a1][d1]--;
		sum[c1][b1]--;
		sum[c1][d1]++;
	}
	for(int i=0; i<nx; i++) for(int j=1; j<ny; j++) sum[i][j]+=sum[i][j-1];
	for(int i=1; i<nx; i++) for(int j=0; j<ny; j++) sum[i][j]+=sum[i-1][j];
	for(int i=0; i<nx-1; i++){
		for(int j=0; j<ny-1; j++){
			if(sum[i][j]>0){
				vl2[vx[i]].push_back({{vy[j], vy[j+1]}, h[e]});
				vr2[vx[i+1]].push_back({{vy[j], vy[j+1]}, h[e]});
			}
		}
	}
}
void calc3(){
	BIT<ll> bit(2*n, [](ll x, ll y){ return (x^y);});
	for(int i=0; i<2*n; i++){
		for(auto p:vl2[i]){
			bit.add(p.first.first+1, p.second);
			bit.add(p.first.second+1, p.second);
		}
		for(auto p:vr2[i]){
			bit.add(p.first.first+1, p.second);
			bit.add(p.first.second+1, p.second);
		}
		for(auto k:vq[i]){
			ans[k]^=bit.sum(q[k]+1);
		}
	}
}
int main()
{
	cin>>n;
	for(int i=0; i<n; i++) scanf("%lld", &h[i]);
	for(int i=0; i<n; i++){
		scanf("%d %d %d %d %d", &a[i], &b[i], &c[i], &d[i], &e[i]);
		e[i]--;
		ind[e[i]].push_back(i);
	}
	cin>>Q;
	for(int i=0; i<Q; i++){
		int pi; scanf("%d %d", &pi, &q[i]);
		vq[pi].push_back(i);
	}
	for(int i=0; i<n; i++){
		if(ind[i].size()>=200) calc(i);
		else calc2(i);
	}
	calc3();
	for(int i=0; i<Q; i++){
		printf("%lld\n", ans[i]);
	}
	return 0;
}
0