結果

問題 No.961 Vibrant Fillumination
ユーザー chocoruskchocorusk
提出日時 2019-12-24 01:46:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,690 ms / 5,000 ms
コード長 3,861 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 127,328 KB
実行使用メモリ 149,348 KB
最終ジャッジ日時 2023-10-23 23:47:55
合計ジャッジ時間 21,992 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,632 KB
testcase_01 AC 4 ms
13,632 KB
testcase_02 AC 265 ms
21,184 KB
testcase_03 AC 271 ms
21,116 KB
testcase_04 AC 270 ms
21,176 KB
testcase_05 AC 267 ms
21,192 KB
testcase_06 AC 269 ms
21,188 KB
testcase_07 AC 268 ms
21,184 KB
testcase_08 AC 271 ms
21,180 KB
testcase_09 AC 272 ms
21,200 KB
testcase_10 AC 216 ms
27,880 KB
testcase_11 AC 219 ms
27,948 KB
testcase_12 AC 218 ms
27,956 KB
testcase_13 AC 220 ms
27,796 KB
testcase_14 AC 218 ms
29,088 KB
testcase_15 AC 212 ms
27,136 KB
testcase_16 AC 220 ms
28,852 KB
testcase_17 AC 213 ms
27,620 KB
testcase_18 AC 220 ms
28,076 KB
testcase_19 AC 218 ms
27,724 KB
testcase_20 AC 220 ms
27,696 KB
testcase_21 AC 215 ms
27,196 KB
testcase_22 AC 214 ms
27,344 KB
testcase_23 AC 210 ms
26,692 KB
testcase_24 AC 217 ms
27,580 KB
testcase_25 AC 215 ms
27,952 KB
testcase_26 AC 173 ms
22,404 KB
testcase_27 AC 190 ms
23,120 KB
testcase_28 AC 174 ms
22,412 KB
testcase_29 AC 193 ms
23,384 KB
testcase_30 AC 157 ms
19,256 KB
testcase_31 AC 147 ms
18,112 KB
testcase_32 AC 163 ms
20,480 KB
testcase_33 AC 4 ms
13,628 KB
testcase_34 AC 1,690 ms
149,348 KB
testcase_35 AC 1,267 ms
20,916 KB
testcase_36 AC 916 ms
21,020 KB
testcase_37 AC 721 ms
20,928 KB
testcase_38 AC 602 ms
20,884 KB
testcase_39 AC 534 ms
20,932 KB
testcase_40 AC 483 ms
20,996 KB
testcase_41 AC 444 ms
21,056 KB
testcase_42 AC 392 ms
20,984 KB
testcase_43 AC 374 ms
20,976 KB
testcase_44 AC 355 ms
20,992 KB
testcase_45 AC 336 ms
21,060 KB
testcase_46 AC 322 ms
21,064 KB
testcase_47 AC 320 ms
21,004 KB
testcase_48 AC 306 ms
21,124 KB
testcase_49 AC 298 ms
21,104 KB
権限があれば一括ダウンロードができます

ソースコード

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
    vector<T> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    T sum(int i){
        T s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    void add(int i, T x){
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
template<typename T>
struct BITxor{ //1-indexed
    vector<T> bit;
    int size;
    BITxor(int n):size(n), bit(n+1, 0){}
    T sum(int i){
        T s=0;
        while(i>0){
            s^=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    void add(int i, T x){
        while(i<=size){
            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];
//vector<int> vl[100010], vr[100010];
ll ans[50050];
int q[50050];
vector<int> vq[100010];
void calc(int e){
	if(ind[e].empty()) return;
	BIT<int> bit(2*n);
	vector<int> vl3[100010], vr3[100010];
	for(auto k:ind[e]){
		vl3[a[k]].push_back(k);
		vr3[c[k]].push_back(k);
	}
	for(int i=0; i<2*n; i++){
		for(auto k:vl3[i]){
			bit.add(b[k]+1, 1);
			bit.add(d[k]+1, -1);
		}
		for(auto k:vr3[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];
			}
		}
	}
}
int sum[110][110];
vector<Pl> vl2[100010], vr2[100010];
void calc2(int e){
	vector<int> vx, vy;
	for(auto k:ind[e]){
		vx.push_back(a[k]);
		vx.push_back(c[k]);
		vy.push_back(b[k]);
		vy.push_back(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(){
	BITxor<ll> bit(2*n);
	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++) cin>>h[i];
	for(int i=0; i<n; i++){
		cin>>a[i]>>b[i]>>c[i]>>d[i]>>e[i];
		e[i]--;
		ind[e[i]].push_back(i);
		//vl[a[i]].push_back(i);
		//vr[c[i]].push_back(i);
	}
	cin>>Q;
	for(int i=0; i<Q; i++){
		int pi; cin>>pi>>q[i];
		vq[pi].push_back(i);
	}
	for(int i=0; i<n; i++){
		if(ind[i].size()>=50){
			calc(i);
		}else{
			calc2(i);
		}
	}
	calc3();
	for(int i=0; i<Q; i++){
		printf("%lld\n", ans[i]);
	}
	return 0;
}
0