构造。
比较骚的构造题。肯定可以构造出$min(R-L+1)$,只要$0$ $1$ $2$ $...$ $R-L$ $0$ $1$ $2$ $...$ $R-L$填数字即可,这样任意一段区间都包含了$0$ $1$ $2$ $...$ $R-L$。
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<ctime> #include<iostream> using namespace std; typedef long long LL; const double pi=acos(-1.0); void File() { freopen("D:\\in.txt","r",stdin); freopen("D:\\out.txt","w",stdout); } template <class T> inline void read(T &x) { char c = getchar(); x = 0; while(!isdigit(c)) c = getchar(); while(isdigit(c)) { x = x * 10 + c - ‘0‘; c = getchar(); } } int n,m; int main() { cin>>n>>m; int len=600000; for(int i=1;i<=m;i++) { int L,R; cin>>L>>R; len=min(len,R-L+1); } cout<<len<<endl; for(int i=0;i<n;i++) { cout<<(i+len-1)%len<<" "; } cout<<endl; return 0; }
时间: 2024-10-06 15:54:02