QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#516337 | #6755. 方格染色 | PCTprobability | 100 ✓ | 82ms | 16528kb | C++14 | 9.3kb | 2024-08-12 16:14:12 | 2024-08-12 16:14:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define endl "\n"
typedef pair<int, int> Pii;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(x) begin(x), end(x)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(s) (s).begin(),(s).end()
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define FOR_(n) for (ll _ = 0; (_) < (ll)(n); ++(_))
#define FOR(i, n) for (ll i = 0; (i) < (ll)(n); ++(i))
#define se second
#define pb push_back
#define P pair<ll,ll>
#define PQminll priority_queue<ll, vector<ll>, greater<ll>>
#define PQmaxll priority_queue<ll,vector<ll>,less<ll>>
#define PQminP priority_queue<P, vector<P>, greater<P>>
#define PQmaxP priority_queue<P,vector<P>,less<P>>
#define NP next_permutation
#define die(a) {cout<<a<<endl;return 0;}
#define dier(a) {return a;}
//const ll mod = 1000000009;
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 4000000000000000000ll;
const ld eps = ld(0.00000000001);
static const long double pi = 3.141592653589793;
template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];}
template<class T,class K>void vcin(vector<T> &n,vector<K> &m){for(int i=0;i<int(n.size());i++) cin>>n[i]>>m[i];}
template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;}
template<class T>void vcin(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cin>>n[i][j];}}}
template<class T>void vcout(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cout<<n[i][j]<<" ";}cout<<endl;}cout<<endl;}
void yes(bool a){cout<<(a?"yes":"no")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void possible(bool a){ cout<<(a?"possible":"impossible")<<endl; }
void Possible(bool a){ cout<<(a?"Possible":"Impossible")<<endl; }
void POSSIBLE(bool a){ cout<<(a?"POSSIBLE":"IMPOSSIBLE")<<endl; }
#define FOR_R(i, n) for (ll i = (ll)(n)-1; (i) >= 0; --(i))
template<class T>auto min(const T& a){ return *min_element(all(a)); }
//template<class T>auto max(const T& a){ return *max_element(all(a)); }
template<class T,class F>void print(pair<T,F> a){cout<<a.fi<<" "<<a.se<<endl;}
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 (b<a) { a=b; return 1; } return 0;}
template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
ll fastgcd(ll u,ll v){ll shl=0;while(u&&v&&u!=v){bool eu=!(u&1);bool ev=!(v&1);if(eu&&ev){++shl;u>>=1;v>>=1;}else if(eu&&!ev){u>>=1;}else if(!eu&&ev){v>>=1;}else if(u>=v){u=(u-v)>>1;}else{ll tmp=u;u=(v-u)>>1;v=tmp;}}return !u?v<<shl:u<<shl;}
ll modPow(ll a, ll n, ll mod) { if(mod==1) return 0;ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
vector<ll> divisor(ll x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / ans[i]);}}}sor(ans); return ans; }
ll pop(ll x){return __builtin_popcountll(x);}
ll poplong(ll x){ll y=-1;while(x){x/=2;y++;}return y;}
P hyou(P a){ll x=fastgcd(abs(a.fi),abs(a.se));a.fi/=x;a.se/=x;if(a.se<0){a.fi*=-1;a.se*=-1;}return a;}
P Pplus(P a,P b){ return hyou({a.fi*b.se+b.fi*a.se,a.se*b.se});}
P Ptimes(P a,ll b){ return hyou({a.fi*b,a.se});}
P Ptimes(P a,P b){ return hyou({a.fi*b.fi,a.se*b.se});}
P Pminus(P a,P b){ return hyou({a.fi*b.se-b.fi*a.se,a.se*b.se});}
P Pgyaku(P a){ return hyou({a.se,a.fi});}
void cincout(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout<< fixed << setprecision(15);
}
struct seg_tree{
vector<ll> node;
ll n;
seg_tree(ll N){
n=1;
while(n<N) n*=2;
node.resize(2*n);
}
void set(ll x,ll v){
x+=n;
while(x){
node[x]+=v;
x/=2;
}
}
ll prod(ll l,ll r,ll a,ll b,ll k){
if(r<=a||b<=l) return 0;
if(l<=a&&b<=r) return node[k];
return prod(l,r,a,(a+b)/2,2*k)+prod(l,r,(a+b)/2,b,2*k+1);
}
ll prod(ll l,ll r){
return prod(l,r,0,n,1);
}
};
int main(){
cincout();
ll type;
cin>>type;
ll n,m,q;
cin>>n>>m>>q;
vector<vector<ll>> a,b,c;
//vector<vector<ll>> r(n,vector<ll>(m));
//vector<vector<ll>> r1(n,vector<ll>(m)),r2(n,vector<ll>(m));
for(int i=0;i<q;i++){
ll t;
cin>>t;
//t=rand()%2+1;
if(t==1){
ll x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
x1--;
y1--;
x2--;
y2--;
/*
y1=rand()%m;
y2=y1;
x1=rand()%n;
x2=rand()%n;
*/
if(x1>x2) swap(x1,x2);
a.pb({x1,y1,x2,y2});
//cout<<1<<" "<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
//for(int i=x1;i<=x2;i++) r1[i][y1]=1;
}
if(t==2){
ll x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
x1--;
y1--;
x2--;
y2--;
/*
x1=rand()%n;
x2=x1;
y1=rand()%m;
y2=rand()%m;
*/
if(y1>y2) swap(y1,y2);
//cout<<2<<" "<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
b.pb({x1,y1,x2,y2});
//for(int i=y1;i<=y2;i++) r2[x1][i]=1;
}
if(t==3){
ll x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
x1--;
y1--;
x2--;
y2--;
c.pb({x1,y1,x2,y2});
//for(int i=0;i<=x2-x1;i++) r[x1+i][y1+i]=1;
}
}
//共通を除く
ll ans=0;
map<ll,vector<P>> a1,b1,c1;
{
map<ll,vector<P>> m;
for(auto e:a){
m[e[1]].pb({e[0],e[2]});
}
a.clear();
for(auto &e:m){
sor(e.se);
int i=0;
a1[e.fi].pb({-inf,-inf});
a1[e.fi].pb({inf,inf});
while(i<e.se.size()){
ll l=e.se[i].fi;
ll r=e.se[i].se;
while(i+1<e.se.size()&&e.se[i+1].fi<=r){
chmax(r,e.se[i+1].se);
i++;
}
ans+=r-l+1;
a1[e.fi].pb({l,r});
a.push_back({e.fi,l,r});
i++;
}
}
}
{
map<ll,vector<P>> m;
for(auto e:b){
m[e[0]].pb({e[1],e[3]});
}
b.clear();
for(auto &e:m){
sor(e.se);
int i=0;
b1[e.fi].pb({-inf,-inf});
b1[e.fi].pb({inf,inf});
while(i<e.se.size()){
ll l=e.se[i].fi;
ll r=e.se[i].se;
while(i+1<e.se.size()&&e.se[i+1].fi<=r){
chmax(r,e.se[i+1].se);
i++;
}
b1[e.fi].pb({l,r});
ans+=r-l+1;
b.push_back({e.fi,l,r});
i++;
}
}
}
for(auto &e:a1){
sor(e.se);
}
for(auto &e:b1){
sor(e.se);
}
{
map<ll,vector<P>> m;
for(auto e:c){
m[e[1]-e[0]].pb({e[0],e[2]});
}
c.clear();
for(auto &e:m){
sor(e.se);
int i=0;
while(i<e.se.size()){
ll l=e.se[i].fi;
ll r=e.se[i].se;
while(i+1<e.se.size()&&e.se[i+1].fi<=r){
chmax(r,e.se[i+1].se);
i++;
}
//{l,l+e.fi} から {r,r+e.fi} まで
ans+=r-l+1;
ll v=e.fi;
vector<ll> xa,xb;
for(auto e:a){
//{e[1],e[0]} から {e[2],e[0]}
//{l,l+e.fi} から {r,r+e.fi} まで
ll k=e[0]-v;
if(l<=k&&k<=r&&e[1]<=k&&k<=e[2]){
xa.pb(k);
ans--;
}
}
for(auto e:b){
//{e[0],e[1]} から {e[0],e[2]}
//{l,l+e.fi} から {r,r+e.fi} まで
ll k=e[0];
if(l<=k&&k<=r&&e[1]<=k+v&&k+v<=e[2]){
//cout<<e[0]<<" "<<e[1]<<" "<<e[2]<<" "<<l<<" "<<k<<" "<<r<<" "<<v<<endl;
xb.pb(k);
ans--;
}
}
sor(xa);
sor(xb);
xb.pb(inf);
for(auto e:xa) if(*lower_bound(xb.begin(),xb.end(),e)==e) ans++;
i++;
}
}
}
//{a,b} の共通を除く
//a を削除する -> a を追加する -> b の範囲を求める
vector<vector<ll>> iv;
map<ll,ll> z;
for(auto e:a) z[e[0]]++;
for(auto e:b){
z[e[1]]++;
z[e[2]]++;
}
ll now=0;
for(auto &e:z){
e.se=now;
now++;
}
for(auto e:a){
iv.push_back({e[1],1ll,z[e[0]]});
iv.push_back({e[2]+1,0ll,z[e[0]]});
}
for(auto e:b){
iv.pb({e[0],2ll,z[e[1]],z[e[2]]});
}
seg_tree seg(z.size());
sor(iv);
ll cnt=0;
//cout<<ans<<endl;
for(auto e:iv){
if(e[1]==0){
//cout<<e[0]<<" "<<e[1]<<" "<<e[2]<<endl;
seg.set(e[2],-1);
}
if(e[1]==1){
//cout<<e[0]<<" "<<e[1]<<" "<<e[2]<<endl;
seg.set(e[2],1);
}
if(e[1]==2){
//cout<<e[0]<<" "<<e[1]<<" "<<e[2]<<" "<<e[3]<<" "<<seg.prod(e[2],e[3]+1)<<endl;
ans-=seg.prod(e[2],e[3]+1);
}
}
cout<<ans<<endl;
/*
ll ans2=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++) ans2+=r[i][j];
}
cout<<ans2<<endl;
*/
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 5
Accepted
time: 1ms
memory: 3580kb
input:
1 300 300 300 2 3 211 3 214 2 55 69 55 110 2 41 231 41 243 2 205 220 205 250 2 157 229 157 252 1 176 78 183 78 2 3 94 3 106 1 9 35 9 35 2 47 290 47 297 1 278 93 288 93 2 41 236 41 236 1 194 60 252 60 2 193 188 193 212 2 3 223 3 230 1 79 13 109 13 1 44 34 180 34 2 195 219 195 227 1 118 26 157 26 1 6 ...
output:
6278
result:
ok 1 number(s): "6278"
Test #2:
score: 5
Accepted
time: 1ms
memory: 3624kb
input:
2 300 300 300 2 85 246 85 256 2 65 278 65 296 2 162 161 162 163 2 55 17 55 25 2 100 33 100 35 1 15 190 43 190 2 85 166 85 173 1 39 15 48 15 2 252 1 252 5 1 244 88 250 88 2 162 212 162 213 1 17 187 32 187 2 17 23 17 23 2 85 104 85 113 1 21 297 84 297 1 42 21 77 21 2 202 31 202 56 1 216 211 267 211 1 ...
output:
6200
result:
ok 1 number(s): "6200"
Test #3:
score: 5
Accepted
time: 1ms
memory: 3616kb
input:
3 300 300 300 2 116 224 116 238 2 46 87 46 92 2 28 22 28 31 2 283 56 283 131 2 39 242 39 272 1 231 61 264 61 2 116 69 116 86 1 225 60 281 60 2 189 39 189 160 1 24 298 56 298 2 28 159 28 167 1 246 160 285 160 2 177 93 177 120 2 116 168 116 168 1 281 290 283 290 1 277 136 277 136 2 289 268 289 282 1 1...
output:
6639
result:
ok 1 number(s): "6639"
Test #4:
score: 5
Accepted
time: 1ms
memory: 3704kb
input:
4 300 300 300 2 106 122 106 127 2 11 115 11 136 2 73 109 73 139 2 172 52 172 123 2 265 205 265 242 1 120 292 120 292 2 106 97 106 104 1 60 279 133 279 2 233 51 233 65 1 21 198 24 198 2 73 273 73 281 1 64 159 85 159 2 50 54 50 197 2 106 160 106 168 1 248 54 252 54 1 53 59 61 59 2 131 80 131 80 1 55 2...
output:
7078
result:
ok 1 number(s): "7078"
Test #5:
score: 5
Accepted
time: 1ms
memory: 3576kb
input:
5 300 300 300 2 287 265 287 265 2 111 270 111 297 2 157 17 157 58 2 277 275 277 298 2 15 211 15 211 1 14 30 63 30 2 287 84 287 156 1 253 35 295 35 2 20 190 20 194 1 286 33 286 33 2 157 96 157 98 1 91 39 163 39 2 250 8 250 155 2 287 11 287 11 1 300 251 300 251 1 2 17 25 17 2 277 265 277 298 1 29 220 ...
output:
7125
result:
ok 1 number(s): "7125"
Test #6:
score: 5
Accepted
time: 2ms
memory: 3916kb
input:
6 100000 100000 2000 1 18077 90844 29870 90844 1 15898 25209 29023 25209 2 44675 61077 44675 61413 1 99173 18081 99624 18081 2 14413 11091 14413 11125 1 99340 26474 99814 26474 2 96947 75112 96947 80888 2 66129 52517 66129 54954 1 93237 26027 98206 26027 2 78129 62643 78129 85005 1 58541 25209 58885...
output:
9811536
result:
ok 1 number(s): "9811536"
Test #7:
score: 5
Accepted
time: 0ms
memory: 3944kb
input:
7 100000 100000 2000 1 34031 33382 34054 33382 1 99015 33804 99864 33804 2 34512 3505 34512 4898 1 55048 84217 56238 84217 2 38112 40398 38112 42615 1 50442 65899 51889 65899 2 88157 62617 88157 86041 2 60447 86164 60447 92917 1 65226 27267 76959 27267 2 14212 5626 14212 15791 1 8592 33804 10140 338...
output:
10053021
result:
ok 1 number(s): "10053021"
Test #8:
score: 5
Accepted
time: 2ms
memory: 3880kb
input:
8 100000 100000 2000 1 98275 10296 99977 10296 1 73858 63081 78509 63081 2 13466 55377 13466 56714 1 6243 488 9927 488 2 17152 2176 17152 2450 1 54764 65968 58926 65968 2 44370 73685 44370 75926 2 67096 21518 67096 39914 1 451 9553 481 9553 2 68472 48718 68472 62445 1 4999 63081 8847 63081 2 19270 4...
output:
10332321
result:
ok 1 number(s): "10332321"
Test #9:
score: 5
Accepted
time: 2ms
memory: 3880kb
input:
9 100000 100000 2000 1 23317 23871 31852 23871 1 53872 67865 56553 67865 2 72463 7396 72463 8278 1 1541 6200 3500 6200 2 70353 66810 70353 67517 1 13712 70706 14713 70706 2 61832 48509 61832 67304 2 15946 75070 15946 88595 1 12825 45666 19060 45666 2 69012 9660 69012 11970 1 69321 67865 69955 67865 ...
output:
9979747
result:
ok 1 number(s): "9979747"
Test #10:
score: 5
Accepted
time: 63ms
memory: 16292kb
input:
10 100000 100000 100000 1 61835 40902 62028 40902 1 64668 87940 90795 87940 1 61451 55355 61721 55355 1 98743 90394 98811 90394 1 93456 95437 93715 95437 1 178 96457 37434 96457 1 93457 73049 93641 73049 1 19855 25199 20057 25199 1 30835 55620 49371 55620 1 870 22188 35965 22188 1 89651 53076 93078 ...
output:
376451109
result:
ok 1 number(s): "376451109"
Test #11:
score: 5
Accepted
time: 63ms
memory: 14920kb
input:
11 100000 100000 100000 1 93433 32681 94198 32681 1 2415 85702 10653 85702 1 8749 5532 8752 5532 1 4176 3468 7801 3468 1 65135 97514 70898 97514 1 1346 69975 2218 69975 1 7238 53922 7339 53922 1 6680 21587 14606 21587 1 9177 40049 75470 40049 1 2212 26058 49400 26058 1 35015 27905 44587 27905 1 6151...
output:
378527694
result:
ok 1 number(s): "378527694"
Test #12:
score: 5
Accepted
time: 64ms
memory: 15160kb
input:
12 100000 100000 100000 1 644 10293 1177 10293 1 21231 74542 39652 74542 1 43086 28517 43600 28517 1 26256 93913 30489 93913 1 96516 44567 99105 44567 1 61061 42889 82165 42889 1 99983 5181 99987 5181 1 34354 47611 35329 47611 1 9509 65384 12488 65384 1 4173 11791 41138 11791 1 56669 47644 65359 476...
output:
374249547
result:
ok 1 number(s): "374249547"
Test #13:
score: 5
Accepted
time: 56ms
memory: 16528kb
input:
13 100000 100000 100000 1 25010 45828 33332 45828 1 51296 68890 72169 68890 1 78689 23687 78701 23687 1 95867 9382 97806 9382 1 55509 23786 99806 23786 1 40260 60931 44183 60931 1 22221 30731 22226 30731 1 76059 58981 76830 58981 1 7920 60112 15752 60112 1 44688 44084 73628 44084 1 11777 79268 17075...
output:
383211528
result:
ok 1 number(s): "383211528"
Test #14:
score: 5
Accepted
time: 71ms
memory: 15140kb
input:
14 100000 100000 100000 2 80885 49245 80885 49283 2 11220 64102 11220 65000 1 92473 13377 99579 13377 2 80885 86626 80885 86820 2 21118 1259 21118 11985 2 42237 62778 42237 69888 1 97222 79184 98758 79184 2 44599 63597 44599 63713 2 79040 95387 79040 96667 2 69913 88035 69913 88669 2 45307 2924 4530...
output:
381101960
result:
ok 1 number(s): "381101960"
Test #15:
score: 5
Accepted
time: 71ms
memory: 14556kb
input:
15 100000 100000 100000 2 91764 54353 91764 54520 2 28652 49170 28652 49615 1 9331 16798 11503 16798 2 91764 79993 91764 81072 2 84153 26433 84153 32088 2 75533 55981 75533 56009 1 37815 31743 39093 31743 2 6745 3757 6745 3760 2 63642 6258 63642 22771 2 55482 37341 55482 37878 2 81074 74483 81074 88...
output:
382632220
result:
ok 1 number(s): "382632220"
Test #16:
score: 5
Accepted
time: 61ms
memory: 15200kb
input:
16 100000 100000 100000 2 66828 6630 66828 7506 2 62880 34446 62880 43261 1 47672 55311 60293 55311 2 66828 76715 66828 76935 2 363 3447 363 68149 2 63886 41674 63886 55533 1 22133 90250 22411 90250 2 73144 82613 73144 82629 2 29932 19382 29932 22540 2 1995 82720 1995 83239 2 45497 7470 45497 10822 ...
output:
380367856
result:
ok 1 number(s): "380367856"
Test #17:
score: 5
Accepted
time: 65ms
memory: 14672kb
input:
17 100000 100000 100000 2 77793 41255 77793 41333 2 5747 28352 5747 35492 1 14185 60840 15523 60840 2 77793 13667 77793 13709 2 29577 61040 29577 86816 2 65419 21908 65419 21909 1 4053 40767 5023 40767 2 5799 75974 5799 75989 2 56279 2793 56279 5116 2 88847 42645 88847 42947 2 26816 5454 26816 29322...
output:
377356031
result:
ok 1 number(s): "377356031"
Test #18:
score: 5
Accepted
time: 67ms
memory: 14940kb
input:
18 100000 100000 100000 2 1268 88808 1268 88885 2 57502 2110 57502 4367 1 41290 26515 47069 26515 2 1268 26818 1268 27021 2 71149 83597 71149 94531 2 10874 27348 10874 27667 1 43190 25771 43495 25771 2 58647 88335 58647 88418 2 79069 10314 79069 79144 2 40298 5896 40298 6940 2 59012 9576 59012 13924...
output:
381702497
result:
ok 1 number(s): "381702497"
Test #19:
score: 5
Accepted
time: 71ms
memory: 15248kb
input:
19 100000 100000 100000 2 89823 49443 89823 49983 2 80228 97306 80228 97895 1 42598 57336 42786 57336 2 89823 77556 89823 77717 2 66932 24494 66932 55405 2 53340 64541 53340 64712 1 60745 97405 69512 97405 2 40429 2913 40429 3039 2 81959 82182 81959 90993 2 8781 67985 8781 68397 2 78315 7314 78315 3...
output:
380715962
result:
ok 1 number(s): "380715962"
Test #20:
score: 5
Accepted
time: 82ms
memory: 16112kb
input:
20 1000000000 1000000000 100000 2 94971842 653040809 94971842 653703458 2 482724716 383575122 482724716 435099343 1 318102608 972959400 378877390 972959400 2 94971842 860758970 94971842 863268182 2 367852389 787409469 367852389 998707870 2 419520406 173007646 419520406 446320624 1 89956469 295257477...
output:
3930560445242
result:
ok 1 number(s): "3930560445242"
Extra Test:
score: 0
Extra Test Passed