Submission #793267

# Submission time Handle Problem Language Result Execution time Memory
793267 2023-07-25T17:01:49 Z Antekb Minerals (JOI19_minerals) C++17
70 / 100
35 ms 3836 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+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++){
		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, LL, a, 0);
	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:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  152 |   if(i+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:164:7: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
  164 |   if(t!=prv ^ b ^ 1){
      |      ~^~~~~
minerals.cpp: In function 'void solve(vi)':
minerals.cpp:186:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  186 |  for(int i=0; i<V2.size(); i++){
      |               ~^~~~~~~~~~
minerals.cpp:192:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  192 |  for(int i=0; i<V.size(); i++){
      |               ~^~~~~~~~~
minerals.cpp:199:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  199 |  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 0 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 592 KB Output is correct
4 Correct 8 ms 976 KB Output is correct
5 Correct 13 ms 1488 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 0 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 592 KB Output is correct
8 Correct 8 ms 976 KB Output is correct
9 Correct 13 ms 1488 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 9 ms 1232 KB Output is correct
12 Correct 12 ms 1624 KB Output is correct
13 Correct 10 ms 1616 KB Output is correct
14 Correct 10 ms 1488 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 0 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 592 KB Output is correct
8 Correct 8 ms 976 KB Output is correct
9 Correct 13 ms 1488 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 9 ms 1232 KB Output is correct
12 Correct 12 ms 1624 KB Output is correct
13 Correct 10 ms 1616 KB Output is correct
14 Correct 10 ms 1488 KB Output is correct
15 Correct 33 ms 3792 KB Output is correct
16 Correct 33 ms 3664 KB Output is correct
17 Correct 28 ms 3732 KB Output is correct
18 Correct 29 ms 3664 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 0 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 592 KB Output is correct
8 Correct 8 ms 976 KB Output is correct
9 Correct 13 ms 1488 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 9 ms 1232 KB Output is correct
12 Correct 12 ms 1624 KB Output is correct
13 Correct 10 ms 1616 KB Output is correct
14 Correct 10 ms 1488 KB Output is correct
15 Correct 33 ms 3792 KB Output is correct
16 Correct 33 ms 3664 KB Output is correct
17 Correct 28 ms 3732 KB Output is correct
18 Correct 29 ms 3664 KB Output is correct
19 Incorrect 35 ms 3836 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -
# 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 0 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 592 KB Output is correct
8 Correct 8 ms 976 KB Output is correct
9 Correct 13 ms 1488 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 9 ms 1232 KB Output is correct
12 Correct 12 ms 1624 KB Output is correct
13 Correct 10 ms 1616 KB Output is correct
14 Correct 10 ms 1488 KB Output is correct
15 Correct 33 ms 3792 KB Output is correct
16 Correct 33 ms 3664 KB Output is correct
17 Correct 28 ms 3732 KB Output is correct
18 Correct 29 ms 3664 KB Output is correct
19 Incorrect 35 ms 3836 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -
# 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 0 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 592 KB Output is correct
8 Correct 8 ms 976 KB Output is correct
9 Correct 13 ms 1488 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 9 ms 1232 KB Output is correct
12 Correct 12 ms 1624 KB Output is correct
13 Correct 10 ms 1616 KB Output is correct
14 Correct 10 ms 1488 KB Output is correct
15 Correct 33 ms 3792 KB Output is correct
16 Correct 33 ms 3664 KB Output is correct
17 Correct 28 ms 3732 KB Output is correct
18 Correct 29 ms 3664 KB Output is correct
19 Incorrect 35 ms 3836 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -
# 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 0 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 592 KB Output is correct
8 Correct 8 ms 976 KB Output is correct
9 Correct 13 ms 1488 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 9 ms 1232 KB Output is correct
12 Correct 12 ms 1624 KB Output is correct
13 Correct 10 ms 1616 KB Output is correct
14 Correct 10 ms 1488 KB Output is correct
15 Correct 33 ms 3792 KB Output is correct
16 Correct 33 ms 3664 KB Output is correct
17 Correct 28 ms 3732 KB Output is correct
18 Correct 29 ms 3664 KB Output is correct
19 Incorrect 35 ms 3836 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -
# 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 0 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 592 KB Output is correct
8 Correct 8 ms 976 KB Output is correct
9 Correct 13 ms 1488 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 9 ms 1232 KB Output is correct
12 Correct 12 ms 1624 KB Output is correct
13 Correct 10 ms 1616 KB Output is correct
14 Correct 10 ms 1488 KB Output is correct
15 Correct 33 ms 3792 KB Output is correct
16 Correct 33 ms 3664 KB Output is correct
17 Correct 28 ms 3732 KB Output is correct
18 Correct 29 ms 3664 KB Output is correct
19 Incorrect 35 ms 3836 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -