问你 从某年某月某日到某年某月某日 日期中有多少9。
没看见T很大,超时一发。
然后记录年分前缀和就过了。
#include<string>
#include<vector>
#include<queue>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<set>
#define ll long long
#define x first
#define y second
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int mod=11;
const int maxn=1e4+100;
int y1,m1,d1,y2,m2,d2;
int mo[14]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int y[maxn];
bool judge(int x){
if(x%400==0||(x%4==0&&x%100!=0))return true;
return false;
}
int check(int x){
int ret=0;
while(x){
if(x%10==9) ret++;
x/=10;
}
return ret;
}
void init(){
for(int i=1;i<=10000;++i){
y[i]=y[i-1];
if(judge(i)) y[i]+=66+check(i)*366;
else y[i]+=65+check(i)*365;
}
}
int main(){
init();
int T;
cin>>T;
while(T--){
ll ans=0,run=0,nr=0;
scanf("%d %d %d %d %d %d",&y1,&m1,&d1,&y2,&m2,&d2);
int q1=check(y1),q2=check(y2);
int t=0,t1=0;
for(int i=1;i<m1;++i){
if(i==2){
if(judge(y1)) t+=3+q1*(mo[i]+1);
else t+=2+q1*mo[i];
}
else t+=3+q1*mo[i];
if(i==9) t+=30;
}
for(int i=1;i<d1;++i)
if(i==9||i==19||i==29) t+=1+q1;
else t+=q1;
if(m1==9) t+=d1-1;
for(int i=1;i<m2;++i){
if(i==2){
if(judge(y2)) t1+=3+q2*(mo[i]+1);
else t1+=2+q2*mo[i];
}
else t1+=3+q2*mo[i];
if(i==9) t1+=30;
}
for(int i=1;i<=d2;++i)
if(i==9||i==19||i==29) t1+=1+q2;
else t1+=q2;
if(m2==9) t1+=d2;
int s=0;
if(judge(y1)) s=66+q1*366;
else s=65+q1*365;
if(y1==y2) ans+=(t1-t);
else ans+=s-t+t1;
if(y2>y1)
ans+=y[y2-1]-y[y1];
printf("%lld\n",ans);
}
return 0;
}