Sxxxw

704

Sxxxw
30天前
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=2000010;

int A,B,C,m;
LL s[N],b[N],bp[N];
int d[8][4]={
{0, 0, 0, 1},
{0, 0, 1, -1},
{0, 1, 0, -1},
{0, 1, 1, 1},
{1, 0, 0, -1},
{1, 0, 1, 1},
{1, 1, 0, 1},
{1, 1, 1, -1},
};
int op[N / 2][7];
int get(int i,int j,int k){
return (i*B+j)*C+k;
}

bool check(int mid){
memcpy(b,bp,sizeof b);
for(int i=1;i<=mid;i++){
int x1 = op[i][0], x2 = op[i][1], y1 = op[i][2], y2 = op[i][3], z1 = op[i][4], z2 = op[i][5], h = op[i][6];
b[get(x1,     y1,     z1)]     -= h;
b[get(x1,     y1,     z2 + 1)] += h;
b[get(x1,     y2 + 1, z1)]     += h;
b[get(x1,     y2 + 1, z2 + 1)] -= h;
b[get(x2 + 1, y1,     z1)]     += h;
b[get(x2 + 1, y1,     z2 + 1)] -= h;
b[get(x2 + 1, y2 + 1, z1)]     -= h;
b[get(x2 + 1, y2 + 1, z2 + 1)] += h;
}

memset(s,0,sizeof s);
for (int i = 1; i <= A; i ++ )
for (int j = 1; j <= B; j ++ )
for (int k = 1; k <= C; k ++ ){
s[get(i,j,k)]=b[get(i,j,k)];
for(int u=1;u<8;u++){
int x = i - d[u][0], y = j - d[u][1], z = k - d[u][2], t = d[u][3];
s[get(i, j, k)] -= s[get(x, y, z)] * t;
}

if (s[get(i, j, k)] < 0) return true;
}
return false;
}
int main(){
scanf("%d%d%d%d",&A,&B,&C,&m);
for(int i=1;i<=A;i++)
for(int j=1;j<=B;j++)
for(int k=1;k<=C;k++)
scanf("%lld",&s[get(i,j,k)]);
for(int i=1;i<=A;i++)
for(int j=1;j<=B;j++)
for(int k=1;k<=C;k++)
for(int u=0;u<8;u++){
int x=i-d[u][0],y=j-d[u][1],z=k-d[u][2],t=d[u][3];
bp[get(i,j,k)]+=s[get(x,y,z)]*t;
}
for(int i=1;i<=m;i++)
for(int j=0;j<7;j++)
scanf("%d",&op[i][j]);
int l=1,r=m;
while(l<r){
int mid=l+r>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
printf("%d\n",r);
return 0;
}


Sxxxw
30天前
#include<iostream>
#include<cstdio>
using namespace std;
const int N=1010;
int n,m,q;
int a[N][N],b[N][N];

void insert(int x1,int y1,int x2,int y2,int c){
b[x1][y1]+=c;
b[x1][y2+1]-=c;
b[x2+1][y1]-=c;
b[x2+1][y2+1]+=c;
}
int main(){
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%d",&a[i][j]);
insert(i,j,i,j,a[i][j]);
}
}
while(q--){
int x1,y1,x2,y2,c;
cin>>x1>>y1>>x2>>y2>>c;
insert(x1,y1,x2,y2,c);
}

for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
a[i][j]=a[i-1][j]+a[i][j-1]-a[i-1][j-1]+b[i][j];
printf("%d ",a[i][j]);
}
puts("");
}
return 0;
}


Sxxxw
30天前
#include<iostream>
using namespace std;
const int N=100010;
int m,n;
int a[N],b[N];
void insert(int l,int r,int c ){
b[l]+=c;
b[r+1]-=c;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++) {cin>>a[i]; insert(i,i,a[i]);}

for(int i=1;i<=m;i++){
int l,r,c;
cin>>l>>r>>c;
insert(l,r,c);
}
for(int i=1;i<=n;i++){
a[i]=a[i-1]+b[i];
cout<<a[i]<<" ";
}
return 0;
}


Sxxxw
1个月前
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

bool check(int date){
int year=date/10000;
int month=date/100%100;
int day=date%100;
if(month<=0||month>12) return false;
if(day==0||month!=2&&day>days[month]) return false;
if(month==2){
int leap=year%100&&year%4==0||year%400==0;
if(day>28+leap) return false;
}
return true;
}
int main(){
int date1,date2;
cin>>date1>>date2;
int res=0;
for(int i=1000;i<10000;i++){
int date=i,x=i;
for(int j=0;j<4;j++){
date=date*10+x%10;
x=x/10;
}
if(date1<=date&&date2>=date&&check(date)) res++;
}

cout<<res<<endl;
return 0;
}



Sxxxw
1个月前
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int N=100100;
int line;
int cnt[N];
int res1,res2;
int main(){
cin>>line;
int amax=0,amin=100100,a;
while(line--){
while(cin>>a){
cnt[a]++;
amax=max(a,amax);
amin=min(a,amin);
}
}

for(int i=amin;i<amax;i++){
if(cnt[i]==0) res1=i;
else if(cnt[i]==2) res2=i;
}
cout<<res1<<" "<<res2<<endl;
return 0;
}

#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=100100;
int cnt;
int a[N];
bool f[N];
int n,res1,res2;
int main(){
cin>>cnt;
string line;
getline(cin,line);
while(cnt--){
getline(cin,line);
stringstream ssin(line);
while(ssin>>a[n]) n++;
}
for(int i=0;i<n;i++){
if(f[a[i]]) res2=a[i];
else f[a[i]]=true;
}
int start=0;
while(!f[start]) start++;
for(int i=start;i<=100100;i++){
if(!f[i]){
res1=i;
break;
}
}
cout<<res1<<" "<<res2<<endl;
return 0;
}


Sxxxw
1个月前
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int res;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
int x=i;
while(x){
int t=x%10;
x=x/10;
if(t==2||t==0||t==1||t==9){
res+=i;
break;
}
}
}
cout<<res<<endl;
return 0;
}


Sxxxw
1个月前
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long LL;
const int N=100010;
int a[N],b[N],c[N];
int as[N],cs[N];  //as[i]代表a[]中有多少小于b[i]
int cnt[N],s[N];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++) scanf("%d",&a[i]),a[i]++;
for(int i=0;i<n;i++) scanf("%d",&b[i]),b[i]++;
for(int i=0;i<n;i++) scanf("%d",&c[i]),c[i]++;
//求as[]
for(int i=0;i<n;i++) cnt[a[i]]++;
for(int i=1;i<N;i++) s[i]=s[i-1]+cnt[i];
for(int i=0;i<n;i++) as[i]=s[b[i]-1];

//求cs[]
memset(cnt,0,sizeof cnt);
memset(s,0,sizeof s);
for(int i=0;i<n;i++) cnt[c[i]]++;
for(int i=1;i<N;i++) s[i]=s[i-1]+cnt[i];
for(int i=0;i<n;i++) cs[i]=s[N-1]-s[b[i]];

LL res=0;
for(int i=0;i<n;i++) res+=(LL)as[i]*cs[i];

cout<<res<<endl;

return 0;
}


Sxxxw
1个月前
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=10010,INF=100000;
int a[N];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
int res=0;
for(int i=0;i<n;i++){   //左端点
int maxv=-INF,minv=INF;
for(int j=i;j<n;j++){  //右端点
maxv=max(maxv,a[j]);
minv=min(minv,a[j]);
if(maxv-minv==j-i) res++;  //排列问题，没有重复数字
}                              //当最大减去最小等于数组长度时，说明连续
}
cout<<res<<endl;
return 0;
}


Sxxxw
1个月前
#include <iostream>
#include <cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,k;
const int N=26,mod=1000000007;
int w[55][55];
int f[55][55][13][14];
int main()
{
scanf("%d %d %d",&n,&m,&k);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>w[i][j];
w[i][j]++;
}
}
f[1][1][1][w[1][1]]=1;
f[1][1][0][0]=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(i==1&&j==1) continue;
for(int u=0;u<=k;u++){
for(int v=0;v<=13;v++){
f[i][j][u][v]=(f[i][j][u][v]+f[i-1][j][u][v])%mod;
f[i][j][u][v]=(f[i][j][u][v]+f[i][j-1][u][v])%mod;
if(w[i][j]==v&&u>0){
for(int c=0;c<v;c++){
f[i][j][u][v]=(f[i][j][u][v]+f[i-1][j][u-1][c])%mod;
f[i][j][u][v]=(f[i][j][u][v]+f[i][j-1][u-1][c])%mod;
}
}
}
}
}
}
int res=0;
for(int i=0;i<=13;i++){
res=(res+f[n][m][k][i])%mod;
}
cout<<res<<endl;
return 0;
}


Sxxxw
3个月前
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1010;
int a[N],f[N];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++){
f[i]=1;
for(int j=1;j<i;j++){
if(a[j]<a[i]) { f[i]=max(f[i],f[j]+1);}
}
}
int res=0;
for(int i=1;i<=n;i++){
res=max(res,f[i]);
}
cout<<res<<endl;
return 0;
}