cpp
#include<iostream>
#include<string>
#include<stack>
#include<vector>
using namespace std;
const int N=200005;
int a[N];
void solve(){
int n;
cin>>n;
vector<int>b,c;
int ma=-1;
for(int i=0;i<n;i++){
cin>>a[i];
ma=max(a[i],ma);
}
for(int i=0;i<n;i++){
if(a[i]==ma)c.push_back(a[i]);
else b.push_back(a[i]);
}
if(b.size()==0||c.size()==0){
cout<<"-1"<<endl;
}
else {
cout<<b.size()<<' '<<c.size()<<endl;
for(int i=0;i<b.size();i++){
cout<<b[i]<<' ';
}
cout<<"\n";
for(int i=0;i<c.size();i++){
cout<<c[i]<<' ';
}
cout<<"\n";
}
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
cpp
#include<iostream>
#include<string>
#include<stack>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstdio>
using namespace std;
const int N=200005;
int a[N];
void solve(){
int n;
cin>>n;
vector<int>ans;
int mi=1e9+6;
for(int i=0;i<n;i++){
int m;
scanf("%d",&m);
priority_queue<int,vector<int>,greater<int> >q;
for(int i=0;i<m;i++){
int x;
scanf("%d",&x);
mi=min(mi,x);
q.push(x);
}
q.pop();
ans.push_back(q.top());
}
long long res=0;
sort(ans.begin(),ans.end());
for(int i=1;i<ans.size();i++){
res+=ans[i];
}
res+=mi;
cout<<res<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
cpp
#include<iostream>
#include<string>
#include<stack>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstdio>
using namespace std;
const int N=200005;
int a[N];
void solve(){
int n;
cin>>n;
int ans=-1;int q=n;
for(int k=0;k<=q;k++){
for(int i=1;i<=k;i++){
a[i]=i;
}
n=q;
for(int i=k+1;i<=q;i++){
a[i]=n--;
}
long long p1=0;
for(int i=1;i<=q;i++)p1+=a[i]*i;
int ma=-1;
for(int i=1;i<=q;i++)ma=max(a[i]*i,ma);
if(ans<p1-ma)ans=p1-ma;}
cout<<ans<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
Status - Codeforces Round 892 (Div. 2) - Codeforces(很好的一道题,主意cin会超时)
cpp
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int>PII;
const int N=200005;
void solve(){
int n;
cin>>n;
vector<PII>q;
vector<PII>ans;
for(int i=1;i<=n;i++){
int l,r,a,b;
cin>>l>>r>>a>>b;
q.push_back({l,b});
}
sort(q.begin(),q.end());
for(int i=0;i<n;){
int x=q[i].first,y=q[i].second;
while(i<n&&q[i].first<=y){
y=max(q[i].second,y);
i++;
}
ans.push_back({x,y});
}
int t;
cin>>t;
while(t--){
int x;
cin>>x;
int l=0,r=ans.size()-1;
while(l<r){
int mid=l+r+1>>1;
if(ans[mid].first<=x)l=mid;
else r=mid-1;
}
if(ans[l].first<=x&&ans[l].second>=x)cout<<ans[l].second<<' ';
else cout<<x<<' ';
}
cout<<endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
}
cpp
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
typedef pair<int,int>PII;
typedef long long ll;
const int N=1000006;
bool is[N];
int cnt;
int prim[N];
void isp(int n){
memset(is,0,sizeof(0));
cnt=0;
for(int i=2;i<n;i++){
if(!is[i]){
prim[cnt++]=i;
if(i*i<n){
for(int j=i*i;j<n;j+=i){
is[j]=1;
}
}
}
}
}
void solve(){
long long n,m;
cin>>n>>m;
ll ans=1e16;
for(long long i=1;i*i-1000000<=m&&i<=n;i++){
ll l=1,r=n;
if(r*i<m)continue;
while(r>l){
ll mid=r+l>>1;
if(mid*i<m)l=mid+1;
else r=mid;
}
if(ans>i*l&&i*l>=m&&i<=n&&l<=n){
ans=i*l;
}
}
if(ans!=1e16)cout<<ans<<endl;
else cout<<-1<<endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
}
[ABC295D] Three Days Ago - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)(类似前缀和)
cpp
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
map<string,int>ma;
void solve(){
string s;
cin>>s;
int n=s.size();
long long ans=0;
string sum="0000000000";
ma[sum]++;
for(int i=0;i<n;i++){
int num=s[i]-'0';
sum[num]=(sum[num]=='1'?'0':'1');
ans+=ma[sum];
ma[sum]++;
}
cout<<ans<<endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
}
cpp
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long LL;
//sqrt(2^31 - 1)
const int N = 1e6 + 10;
bool st[N];
int primes[N], cnt;
void get_primes(int n) {
memset(st, 0, sizeof st);
cnt = 0;
for (int i = 2; i <= n; ++ i) {
if (!st[i]) primes[cnt ++ ] = i;
for (int j = 0; primes[j] * i <= n; ++ j) {
st[primes[j] * i] = true;
if (i % primes[j] == 0) break;
}
}
}
int main() {
int l, r;
while (~scanf("%d%d", &l, &r)) {
get_primes(50000);
//把[l,r]区间内所有的合数用他们的最小质因子筛掉
memset(st, 0, sizeof st);
for (int i = 0; i < cnt; ++ i) {
LL p = primes[i];
for (LL j = max(2 * p, (l + p - 1) / p * p); j <= r; j += p)
st[j - l] = true;
}
//剩下的所有的都是素数了
cnt = 0;
for (int i = 0; i <= r - l; ++ i)
if (!st[i] && i + l > 1)
primes[cnt ++ ] = i + l;
if (cnt < 2) printf("There are no adjacent primes.\n");
else {
//计算间隔
int minp = 0, maxp = 0;
for (int i = 0; i + 1 < cnt; ++ i) {
int d = primes[i + 1] - primes[i];
if (d < primes[minp + 1] - primes[minp]) minp = i;
if (d > primes[maxp + 1] - primes[maxp]) maxp = i;
}
printf("%d,%d are closest, %d,%d are most distant.\n",
primes[minp], primes[minp + 1],
primes[maxp], primes[maxp + 1]);
}
}
return 0;
}