zoukankan      html  css  js  c++  java
  • Codeforces 85 D. Sum of Medians

    题目链接:http://codeforces.com/contest/85/problem/D


    做法果然男默女泪啊.....

    大概就是直接开了一个$vector$每次插入删除都用自带的$insert$和$erase$,然后查询也是暴力搞。

    那么为啥么过得很有理有据呢?

      1.首先考虑如果没有修改我就能继承上一次的答案...

      2.修改我们假设(就是)${O(logn)}$的。

      3.每次暴力查询是$5$个数字一步。

      4.显然一开始并不是上来就有${100000}$个数字

    所以大概复杂度会是${O(n^{2}/40)}$的....


     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<vector>
     5 #include<cstdlib>
     6 #include<cmath>
     7 #include<cstring>
     8 using namespace std;
     9 #define maxn 10010
    10 #define llg int
    11 #define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
    12 llg n,m,w,x;
    13 vector<llg>a;
    14 long long ans;
    15 bool pd;
    16 char s[6];
    17 inline int getint()
    18 {
    19        int w=0,q=0; char c=getchar();
    20        while((c<'0' || c>'9') && c!='-') c=getchar(); if(c=='-') q=1,c=getchar(); 
    21        while (c>='0' && c<='9') w=w*10+c-'0', c=getchar(); return q ? -w : w;
    22 }
    23 
    24 int main()
    25 {
    26     yyj("sum");
    27     cin>>n;
    28     while (n--)
    29     {
    30         scanf("%s",s);
    31         if (s[0]=='s')
    32         {
    33             if (!pd) {printf("%lld
    ",ans); continue;}
    34             ans=0;
    35             w=a.size();
    36             for (llg i=2;i<w;i+=5) ans+=a[i];
    37             pd=false;
    38             printf("%lld
    ",ans);
    39         }
    40         else
    41         {
    42             x=getint();
    43             if (s[0]=='a') a.insert(lower_bound(a.begin(),a.end(),x),x);
    44             else a.erase(lower_bound(a.begin(), a.end(), x));  
    45             pd=true;
    46         }
    47     }
    48     return 0;
    49 }

     当然正解也是可以想出来的,就是一个线段树每个点维护所有数字%5=x的数字和,然后记录右移多少。

  • 相关阅读:
    【hdu4285】 circuits
    java代码获取ip地址
    java覆写hashcode方法
    java覆写equals方法
    Linux下Apache服务器并发优化
    异常:cvc-complex-type.2.4.a: Invalid content was found starting with element
    SpringMVC请求访问不到静态文件解决方式
    mina教程
    分布式session
    jsp自定义标签
  • 原文地址:https://www.cnblogs.com/Dragon-Light/p/6613210.html
Copyright © 2011-2022 走看看