Submission #793280

# Submission time Handle Problem Language Result Execution time Memory
793280 2023-07-25T17:14:51 Z Antekb Minerals (JOI19_minerals) C++17
100 / 100
50 ms 5668 KB
#include<bits/stdc++.h>

#pragma GCC optimize("Ofast")
//#pragma GCC optimize("trapv")
 
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define pp(x) pop_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)
 
using namespace std;
 
///~~~~~~~~~~~~~~~~~~~~~~~~~~
 
template <typename H, typename T> 
ostream& operator<<(ostream& os, pair<H, T> m){
	return os <<"("<< m.st<<", "<<m.nd<<")";
}
template <typename H> 
ostream& operator<<(ostream& os, vector<H> V){
	os<<"{";
	for(int i=0; i<V.size(); i++){
		if(i)os<<" ";
		os<<V[i];
	}
	os<<"}";
	return os;
}
 
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
//#define deb(x...) ;
 
///~~~~~~~~~~~~~~~~~~~~~~~~~
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

 
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int K=17, N=1<<K, INF=1e9+5, mod2=1e9+7, mod=998244353;

struct modint{
	int n=0;
	modint(){}
	modint(ll x){
		n=x%mod;
		if(n<0)n+=mod;
	}
	operator int(){
		return n;
	}
	modint operator+(modint a){a.n = n+a.n; if(a.n>=mod)a.n-=mod;return a;}
	modint operator+=(modint a){return (*this)=(*this)+a;}
	modint operator-(modint a){a.n = n-a.n; if(a.n<0)a.n+=mod;return a;}
	modint operator-=(modint a){return (*this)=(*this)-a;}
	modint operator*(modint a){a.n = (n*1ll*a.n)%mod; return a;}
	modint operator*=(modint a){return (*this)=(*this)*a;}
	modint operator^(const ll &m)const{
		modint a(1);
		if(m==0)return a;
		if(m==1)return (*this);
		a=(*this)^(m/2);
		a*=a;
		return a*((*this)^(m&1));
	}
	modint odw(){
		return (*this)^((ll)mod-2);
	}
	modint operator/(modint a){return (*this)*a.odw();}
	modint operator/=(modint a){return (*this)=(*this)/a;}
	bool operator==(modint a){return a.n==n;}
	friend ostream& operator<<(ostream& os, modint m) {
		return os << m.n; 
	}
};
/*modint fact[N], fact2[N];
typedef vector<modint> vm;
void factinit(){
    fact[0]=1;
    for(int i=1; i<N; i++){
        fact[i]=(fact[i-1]*modint(i))%mod;
    }
    fact2[N-1]=fact[N-1].odw();
    for(int i=N-2; i>=0; i--){
    	fact2[i]=(fact2[i+1]*modint(i+1))%mod;
    }
}
modint npok(int _n, int _k){
 	if(_n<_k)return 0;
    return fact[_n]*fact2[_k]*fact2[_n-_k];
}*/
int los(int a, int b){
	return a+(rng())%(b-a+1);
}
#include "minerals.h"
/*vi wynik={0, 2, 0, 1, 4, 3, 2, 1, 3, 4};
int czy_w_srodku[N];
int ile_dobrze=0;
int stan[N];
int rozne=0;
int Query(int x){
	x--;
	czy_w_srodku[x]^=1;
	if(czy_w_srodku[x]){
		if(!stan[wynik[x]]++)rozne++;
	}
	else{	
		if(!--stan[wynik[x]])rozne--;
	}
	return rozne;
}
void Answer(int a, int b){
	deb(a, b, wynik[a-1], wynik[b-1]);
	assert(wynik[a-1]==wynik[b-1]);
	ile_dobrze++;
}*/
int solve2(vi A, vi B, int wyn, bool b){
	//deb(A, B);
	if(!A.size())return wyn;
	if(A.size()==1){
		Answer(A[0], B[0]);
		return wyn;
	}
	vi AL, AR, BL, BR;
	for(int i=0; i<A.size(); i++){
		if(!i || 3*i<A.size()){
			AL.pb(A[i]);
			wyn=Query(A[i]);
		}
		else{
			AR.pb(A[i]);
			//if(b==1)wyn=Query(A[i]);
		}
	}
	int prv=wyn;
	for(int i=0; i<B.size(); i++){
		if(BL.size()==AL.size()){
			BR.pb(B[i]);
			continue;
		}
		if(BR.size()==AR.size()){
			BL.pb(B[i]);
			continue;
		}
		int t=Query(B[i]);
		if(t!=prv ^ b ^ 1){
			BL.pb(B[i]);
		}
		else BR.pb(B[i]);
		prv=t;
	}
	wyn=solve2(AL, BL, prv, b^1);
	wyn=solve2(AR, BR, wyn, b);
	return wyn;
}
void solve(vi V){
	//deb(V);
	if(V.size()==0)return;
	if(V.size()==2){
		Answer(V[0], V[1]);
		return;
	}
	vi typ(V.size());
	vi V2(V.size());
	iota(all(V2), 0);
	shuffle(all(V2), rng);
	int akt=0;
	for(int i=0; i<V2.size(); i++){
		int now=Query(V[V2[i]]);
		if(now!=akt)typ[V2[i]]++;
		akt=now;
	}
	/*shuffle(all(V2), rng);
	for(int i=0; i<V.size(); i++){
		int now=Query(V[V2[i]]);
		if(now!=akt)typ[V2[i]]+=2;
		akt=now;
	}*/
	//deb(typ);
	vi L, LL, R, RR;
	for(int i=0; i<V.size(); i++){
		if(typ[i]==0)L.pb(V[i]);
		else if(typ[i]==3)LL.pb(V[i]);
		else if(typ[i]==1)R.pb(V[i]);
		else RR.pb(V[i]);
	}
	int a=0;
	a=solve2(L, R, a, 1);
	//a=solve2(R, RR, a, 0);
}
void Solve(int n){
	vector<int> V(n+n);
	iota(all(V), 1);
	solve(V);
}
/*int main(){
	//factinit();
	//BOOST
	int n=10;
	wynik.resize(n+n);
	iota(all(wynik), 2);
	for(int &i:wynik)i/=2;
	assert(wynik.size()==n+n);
	shuffle(all(wynik), rng);
	deb(wynik);
	Solve(n);
	assert(ile_dobrze==n);
}*/

Compilation message

minerals.cpp: In function 'int solve2(vi, vi, int, bool)':
minerals.cpp:151:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  151 |  for(int i=0; i<A.size(); i++){
      |               ~^~~~~~~~~
minerals.cpp:152:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  152 |   if(!i || 3*i<A.size()){
      |            ~~~^~~~~~~~~
minerals.cpp:162:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  162 |  for(int i=0; i<B.size(); i++){
      |               ~^~~~~~~~~
minerals.cpp:172:7: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
  172 |   if(t!=prv ^ b ^ 1){
      |      ~^~~~~
minerals.cpp: In function 'void solve(vi)':
minerals.cpp:194:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  194 |  for(int i=0; i<V2.size(); i++){
      |               ~^~~~~~~~~~
minerals.cpp:207:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  207 |  for(int i=0; i<V.size(); i++){
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 3 ms 720 KB Output is correct
4 Correct 6 ms 1264 KB Output is correct
5 Correct 14 ms 2088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 3 ms 720 KB Output is correct
8 Correct 6 ms 1264 KB Output is correct
9 Correct 14 ms 2088 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 10 ms 1540 KB Output is correct
12 Correct 16 ms 2128 KB Output is correct
13 Correct 12 ms 2180 KB Output is correct
14 Correct 10 ms 2128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 3 ms 720 KB Output is correct
8 Correct 6 ms 1264 KB Output is correct
9 Correct 14 ms 2088 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 10 ms 1540 KB Output is correct
12 Correct 16 ms 2128 KB Output is correct
13 Correct 12 ms 2180 KB Output is correct
14 Correct 10 ms 2128 KB Output is correct
15 Correct 34 ms 5008 KB Output is correct
16 Correct 35 ms 5092 KB Output is correct
17 Correct 34 ms 4992 KB Output is correct
18 Correct 30 ms 4912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 3 ms 720 KB Output is correct
8 Correct 6 ms 1264 KB Output is correct
9 Correct 14 ms 2088 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 10 ms 1540 KB Output is correct
12 Correct 16 ms 2128 KB Output is correct
13 Correct 12 ms 2180 KB Output is correct
14 Correct 10 ms 2128 KB Output is correct
15 Correct 34 ms 5008 KB Output is correct
16 Correct 35 ms 5092 KB Output is correct
17 Correct 34 ms 4992 KB Output is correct
18 Correct 30 ms 4912 KB Output is correct
19 Correct 48 ms 5160 KB Output is correct
20 Correct 35 ms 5080 KB Output is correct
21 Correct 43 ms 5152 KB Output is correct
22 Correct 27 ms 5028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 3 ms 720 KB Output is correct
8 Correct 6 ms 1264 KB Output is correct
9 Correct 14 ms 2088 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 10 ms 1540 KB Output is correct
12 Correct 16 ms 2128 KB Output is correct
13 Correct 12 ms 2180 KB Output is correct
14 Correct 10 ms 2128 KB Output is correct
15 Correct 34 ms 5008 KB Output is correct
16 Correct 35 ms 5092 KB Output is correct
17 Correct 34 ms 4992 KB Output is correct
18 Correct 30 ms 4912 KB Output is correct
19 Correct 48 ms 5160 KB Output is correct
20 Correct 35 ms 5080 KB Output is correct
21 Correct 43 ms 5152 KB Output is correct
22 Correct 27 ms 5028 KB Output is correct
23 Correct 39 ms 5236 KB Output is correct
24 Correct 35 ms 5228 KB Output is correct
25 Correct 32 ms 5236 KB Output is correct
26 Correct 28 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 3 ms 720 KB Output is correct
8 Correct 6 ms 1264 KB Output is correct
9 Correct 14 ms 2088 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 10 ms 1540 KB Output is correct
12 Correct 16 ms 2128 KB Output is correct
13 Correct 12 ms 2180 KB Output is correct
14 Correct 10 ms 2128 KB Output is correct
15 Correct 34 ms 5008 KB Output is correct
16 Correct 35 ms 5092 KB Output is correct
17 Correct 34 ms 4992 KB Output is correct
18 Correct 30 ms 4912 KB Output is correct
19 Correct 48 ms 5160 KB Output is correct
20 Correct 35 ms 5080 KB Output is correct
21 Correct 43 ms 5152 KB Output is correct
22 Correct 27 ms 5028 KB Output is correct
23 Correct 39 ms 5236 KB Output is correct
24 Correct 35 ms 5228 KB Output is correct
25 Correct 32 ms 5236 KB Output is correct
26 Correct 28 ms 5072 KB Output is correct
27 Correct 39 ms 5368 KB Output is correct
28 Correct 50 ms 5268 KB Output is correct
29 Correct 29 ms 5328 KB Output is correct
30 Correct 29 ms 5240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 3 ms 720 KB Output is correct
8 Correct 6 ms 1264 KB Output is correct
9 Correct 14 ms 2088 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 10 ms 1540 KB Output is correct
12 Correct 16 ms 2128 KB Output is correct
13 Correct 12 ms 2180 KB Output is correct
14 Correct 10 ms 2128 KB Output is correct
15 Correct 34 ms 5008 KB Output is correct
16 Correct 35 ms 5092 KB Output is correct
17 Correct 34 ms 4992 KB Output is correct
18 Correct 30 ms 4912 KB Output is correct
19 Correct 48 ms 5160 KB Output is correct
20 Correct 35 ms 5080 KB Output is correct
21 Correct 43 ms 5152 KB Output is correct
22 Correct 27 ms 5028 KB Output is correct
23 Correct 39 ms 5236 KB Output is correct
24 Correct 35 ms 5228 KB Output is correct
25 Correct 32 ms 5236 KB Output is correct
26 Correct 28 ms 5072 KB Output is correct
27 Correct 39 ms 5368 KB Output is correct
28 Correct 50 ms 5268 KB Output is correct
29 Correct 29 ms 5328 KB Output is correct
30 Correct 29 ms 5240 KB Output is correct
31 Correct 42 ms 5512 KB Output is correct
32 Correct 38 ms 5460 KB Output is correct
33 Correct 42 ms 5516 KB Output is correct
34 Correct 34 ms 5356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 3 ms 720 KB Output is correct
8 Correct 6 ms 1264 KB Output is correct
9 Correct 14 ms 2088 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 10 ms 1540 KB Output is correct
12 Correct 16 ms 2128 KB Output is correct
13 Correct 12 ms 2180 KB Output is correct
14 Correct 10 ms 2128 KB Output is correct
15 Correct 34 ms 5008 KB Output is correct
16 Correct 35 ms 5092 KB Output is correct
17 Correct 34 ms 4992 KB Output is correct
18 Correct 30 ms 4912 KB Output is correct
19 Correct 48 ms 5160 KB Output is correct
20 Correct 35 ms 5080 KB Output is correct
21 Correct 43 ms 5152 KB Output is correct
22 Correct 27 ms 5028 KB Output is correct
23 Correct 39 ms 5236 KB Output is correct
24 Correct 35 ms 5228 KB Output is correct
25 Correct 32 ms 5236 KB Output is correct
26 Correct 28 ms 5072 KB Output is correct
27 Correct 39 ms 5368 KB Output is correct
28 Correct 50 ms 5268 KB Output is correct
29 Correct 29 ms 5328 KB Output is correct
30 Correct 29 ms 5240 KB Output is correct
31 Correct 42 ms 5512 KB Output is correct
32 Correct 38 ms 5460 KB Output is correct
33 Correct 42 ms 5516 KB Output is correct
34 Correct 34 ms 5356 KB Output is correct
35 Correct 47 ms 5668 KB Output is correct
36 Correct 43 ms 5616 KB Output is correct
37 Correct 29 ms 5580 KB Output is correct
38 Correct 45 ms 5488 KB Output is correct