[Cnoi 2021]

A [Cnoi2021]幻想乡程序设计大赛

// ExtraTime Common Header Simple over C++14
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tree<pair<ll,int>,null_type,less<pair<ll,int>>,rb_tree_tag,tree_order_statistics_node_update> pset;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rint(x) int x;cin>>x;
#define rll(x) ll x;cin>>x;
#define rs(x) string x;cin>>x;
#define rvi(v,n) vector<int>v(n);for(auto &i:v)cin>>i;
#define rvl(v,n) vector<ll>v(n);for(auto &i:v)cin>>i;
int main(){
	ios::sync_with_stdio(0),cin.tie(0);cin.exceptions(ios::badbit | ios::failbit);
	ll ans=0;
	rint(n)
	rvi(v1,n)rvi(v2,n)
	for(int i=0;i<n;++i)ans+=min(v1[i],v2[i]);
	cout<<ans;
	return 0;
}

B [Cnoi2021]矩阵

// ExtraTime Common Header Simple over C++14
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define rint(x) int x;cin>>x;
#define rll(x) ll x;cin>>x;
#define rs(x) string x;cin>>x;
#define rvi(v,n) vector<int>v(n);for(auto &i:v)cin>>i;
#define rvl(v,n) vector<ll>v(n);for(auto &i:v)cin>>i;
inline int fpow(int a,int b,int p){//a^b mod p; assert(p!=0);
	int ans=1%p,base=a%p;
	for(;b;b/=2){
		if(b&1)ans=(ll)ans*base%p;
		base=(ll)base*base%p;
	}
	return ans;
}
constexpr int mod = (119 << 23) + 1; // 998244353
int main(){
	ios::sync_with_stdio(0),cin.tie(0);cin.exceptions(ios::badbit | ios::failbit);
	rll(n)rll(k)
	if(k==0){
		cout<<n%mod<<'\n';
		return 0;
	}
	else {
		rvl(v1,n);
		rvl(v2,n);
		ll sum1=0,sum2=0;
		for(auto i:v1)(sum1+=i)%=mod;
		for(auto i:v2)(sum2+=i)%=mod;
		ll sum=sum1*sum2%mod;
		if(k==1){
			cout<<(sum+mod)%mod<<'\n';
		}
		else{
			ll p=0;
			for(int i=0;i<n;++i)
			(p+=v1[i]*v2[i]%mod+mod)%=mod;
			cout<<(fpow(p,k-1,mod)*sum%mod+mod)%mod<<'\n';
		}
	}
	return 0;
}

C [Cnoi2021]区间

#include <bits/stdc++.h>
int Query(int x);
void init() { }
using namespace std;
std::pair<int,int> Guess(int n,int c){
	int l=1,r=n;
	vector<int>Llim;
	vector<int>Rlim;
	int cnt=0;
	while(r-l+1>=2){
		int mid1=l+(r-l)/3;
		int mid2=l+(r-l)*2/3;
		int res=Query(mid1);cnt++;
		if(res==1)
			r=mid1-1;
		else if(res==-1){
			l=mid1+1;
			break;
		}
		else if(res==0){
			Llim.push_back(l);
			Llim.push_back(mid1);
			int res2=Query(mid2);cnt++;
			assert(res2!=-1);
			if(res2==0){				
			Rlim.push_back(mid2);
			Rlim.push_back(r);  
			}
			else if(res2==1){
			Rlim.push_back(mid1);
			Rlim.push_back(mid2-1);  	
			}
			break;
		}
	}
	
	if(Llim.empty()&&Rlim.empty()){
		int a=r,canMax=l,canMin=r;
		while(l<=r){
			int mid=l+(r-l)/2;
			int res=Query(mid);cnt++;
			if(res==1)
				r=mid-1,canMin=min(canMin,mid-1);
			else if(res==-1)
				l=mid+1,canMax=max(canMax,mid+1);
			else{
				if(mid<a){a=mid;}
				r=mid-1;
				canMax=max(canMax,mid);
			}
		}
		int b=a;l=canMax,r=canMin;
		while(l<=r){
			int mid=l+(r-l)/2;
			int res=Query(mid);cnt++;
			if(res==1)
				r=mid-1;
			else if(res==-1)
				l=mid+1;
			else{
				if(mid>b){b=mid;}
				l=mid+1;
			}
		}
		return {a,b};
	}
	else{
		int a=Llim[1],b=Rlim[0];
		{
			int l=Llim[0],r=Llim[1];
			while(l<=r){
				int mid=l+(r-l)/2;
				int res=Query(mid);cnt++;
				if(res==1)
					r=mid-1;
				else if(res==-1)
					l=mid+1;
				else{
					if(mid<a){a=mid;}
					r=mid-1;
				}
			}	
		}
		{
			int l=Rlim[0],r=Rlim[1];
			while(l<=r){
				int mid=l+(r-l)/2;
				int res=Query(mid);cnt++;
				if(res==1)
					r=mid-1;
				else if(res==-1)
					l=mid+1;
				else{
					if(mid>b){b=mid;}
					l=mid+1;
				}
			}	
		}
		return {a,b};
	}
}
posted @ 2022-01-31 01:32  opsiff  阅读(65)  评论(0编辑  收藏  举报