3 条题解

  • 8
    @ 2024-11-23 12:56:53

    22 个小时的比赛,竟然还要我用脑子思考...

    排个序就可以知道每个数应该在的位置。我们设原位置为 ss,应该的位置为 tt,则 ss~tt 的位置是一定要排序的。我们可以在一个差分数组上标记,将 ss ~ tt 的位置加上 11 。这个操作是 O(n)O(n) 的。最后再前缀和差分数组,找出有 kk 个位置为 00 ,则最终答案为 nkn-k

    总时间复杂度为 O(nlogn)O(n\log n)

    代码过于简单,就不放了。

    • @ 2025-5-20 16:35:11

      对不起我错了两个小时的比赛就是要用脑子思考

  • 1
    @ 2025-5-27 16:22:13

    屎山代码

    猎潮的骑士是吧

    #include<bits/stdc++.h>
    using namespace std;
    int n;
    int a[1919810];
    int sum;
    bool ll[1919810];
    bool flag=0;
    int m;
    int main(){
    	cin>>n;
    	for(int i=1;i<=n;i++){
    		cin>>a[i];
    		if(a[i]!=i){
    			for(int j=min(a[i],i);j<=max(a[i],i);j++) ll[j]=1;
    		}
    	}
    	for(int j=1;j<=n;j++)if(ll[j]==1)sum++; 
    	cout<<sum;
    	return 0;
    }
    
    
    • 0
      @ 2024-11-23 13:08:22
      #include<bits/stdc++.h>
      using namespace std;
      int n;
      signed main(){
      	cin>>n,cout<<((n==8) ? 4 : n);
      	return 0;
      }
      

      这是正解~~

      • @ 2024-11-23 13:10:26

        叽里咕噜说什么呢

      • @ 2024-11-23 13:23:04

        等会儿就给你卡掉

      • @ 2024-11-23 14:36:11

        卡掉了,但是在比赛时这时正解

    • 1

    信息

    ID
    957
    时间
    1000ms
    内存
    256MiB
    难度
    9
    标签
    (无)
    递交数
    147
    已通过
    14
    上传者