D. Minimum Euler Cycle
題意
給你一個個結點的完全有向圖,求其字典序最小的歐拉回路,輸出到之間的結點爲多少。
思路
構造 找規律 前綴和 二分
結合樣例找規律容易發現路徑爲
1 2 1 3 1 4 1 5 … 1 n
2 3 2 4 2 5 … 2 n
3 4 3 5 3 6 … 3 n
…
1
比賽的時候由於我沒有注意樣例中99995 9998900031 9998900031這一組數據,直接構造是不行的,會TLE。
這裏要用到前綴和+二分了,先前綴和到每個區間末尾有多少個數,然後二分找在哪個區間再結合規律輸出即可。
第一次cf打回比初始分高,希望再接再厲衝藍名!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const ll maxn = 1e6 + 5;
const int N = 1e5 + 5;
ll n,l,r,pre[N];
ll judge(ll x){
if(x>pre[n-1]) return 1;
int a=lower_bound(pre+1,pre+n,x)-pre;
int b=x-pre[a-1];
return (b&1?a:b/2+a);
}
void solve(){
cin>>n>>l>>r;
for(int i=1;i<=n;i++){
pre[i]=pre[i-1]+2*(n-i);
}
for(ll i=l;i<=r;i++){
cout<<judge(i)<<" ";
}
cout<<'\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T;cin>>T;
while(T--){
solve();
}
return 0;
}