跳到正文

题解

题解:P12464 『FCRT / 1 - 1』Seats

fish_love_cat约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
题目
P12464

版本

  1. v1当前

全世界都去写 P1001 题解了,那我来写这题。


观察操作发现除去第一次操作其余是把一个未染色区间分为尽可能等长的两半。

那这个就很好做了啊,我们直接搜索模拟每个区间就行了,加个记忆化速度快的飞起。

时间复杂度应该 O(log⁡n)O(\log n) 的。

C++
#include<bits/stdc++.h>
#define int __int128
using namespace std;
int read(){
    int sum=0,fish=1;
    char c=getchar_unlocked();
    while((c<'0'||c>'9')&&c!='-')c=getchar_unlocked();
    if(c=='-')fish=-1,c=getchar_unlocked();
    while(c>='0'&&c<='9')sum=sum*10+(c-'0'),c=getchar_unlocked();
    return sum*fish;
}
void print(int x){
    if(x<0)putchar('-'),x=-x;
    if(x<10)putchar(x+'0');
    else print(x/10),putchar(x%10+'0');
}
map<int,int>mp;
int solve(int x){
    if(mp[x])return mp[x];
    if(x<=2)return 0;
    x--;
    return mp[x+1]=1+solve(x/2)+solve((x+1)/2);
}
signed main(){
    int n=read();
    if(n<=2)cout<<1;
    else print(2+solve(n-2));
    return 0;
}
原文