zoukankan      html  css  js  c++  java
  • 【CF1252G】Performance Review(线段树)

    题意:

     n,q<=1e5,a[i],b[i][j]<=1e9,保证能力值互不相同,询问之间保留前面的影响

    思路:其实把大于a[1]的看成0,小于的看成1,设第i天小于a[1]的有b[i]个,本质上就是这样一个过程:

    刚开始有b[0]个小于a[1]的,第1天先减去r[1]看是否小于0,若小于0则结束,再加上b[1],以此类推

    由此可见每次询问只是单点修改了b[x],判断的话就是在判最小的前缀和是否<0

    用线段树维护一下最小的前缀和即可

      1 #include<bits/stdc++.h>
      2 using namespace std;
      3 typedef long long ll;
      4 typedef unsigned int uint;
      5 typedef unsigned long long ull;
      6 typedef long double ld;
      7 typedef pair<int,int> PII;
      8 typedef pair<ll,ll> Pll;
      9 typedef vector<int> VI;
     10 typedef vector<PII> VII;
     11 //typedef pair<ll,ll>P;
     12 #define N  200010
     13 //#define M  200010
     14 #define INF 1e9
     15 #define fi first
     16 #define se second
     17 #define MP make_pair
     18 #define pb push_back
     19 #define pi acos(-1)
     20 #define mem(a,b) memset(a,b,sizeof(a))
     21 #define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
     22 #define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
     23 #define lowbit(x) x&(-x)
     24 #define Rand (rand()*(1<<16)+rand())
     25 #define id(x) ((x)<=B?(x):m-n/(x)+1)
     26 #define ls p<<1
     27 #define rs p<<1|1
     28 
     29 const ll MOD=1e9+7,inv2=(MOD+1)/2;
     30       double eps=1e-6;
     31       int dx[4]={-1,1,0,0};
     32       int dy[4]={0,0,-1,1};
     33 
     34 struct node
     35 {
     36     int s,tag;
     37 }t[N<<2];
     38 
     39 vector<int> c[N];
     40 int r[N],b[N],a[N],d[N];
     41 
     42 int read()
     43 {
     44    int v=0,f=1;
     45    char c=getchar();
     46    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
     47    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
     48    return v*f;
     49 }
     50 
     51 void pushdown(int p)
     52 {
     53     if(t[p].tag!=0)
     54     {
     55         t[ls].s+=t[p].tag;
     56         t[rs].s+=t[p].tag;
     57         t[ls].tag+=t[p].tag;
     58         t[rs].tag+=t[p].tag;
     59         t[p].tag=0;
     60     }
     61 }
     62 
     63 void pushup(int p)
     64 {
     65     t[p].s=min(t[ls].s,t[rs].s);
     66 }
     67 
     68 void build(int l,int r,int p)
     69 {
     70     if(l==r)
     71     {
     72         t[p].s=d[l];
     73         t[p].tag=0;
     74         return;
     75     }
     76     int mid=(l+r)>>1;
     77     build(l,mid,ls);
     78     build(mid+1,r,rs);
     79     pushup(p);
     80 }
     81 
     82 void update(int l,int r,int x,int y,int v,int p)
     83 {
     84     if(x<=l&&r<=y)
     85     {
     86         t[p].s+=v;
     87         t[p].tag+=v;
     88         return;
     89     }
     90     pushdown(p);
     91     int mid=(l+r)>>1;
     92     if(x<=mid) update(l,mid,x,y,v,ls);
     93     if(y>mid) update(mid+1,r,x,y,v,rs);
     94     pushup(p);
     95 }
     96 
     97 int main()
     98 {
     99     //freopen("1.in","r",stdin);
    100     int n=read(),m=read(),q=read();
    101     rep(i,1,n) a[i]=read();
    102     rep(i,2,n)
    103      if(a[i]<a[1]) b[0]++;
    104     r[0]=0;
    105     rep(i,1,m)
    106     {
    107         r[i]=read();
    108         b[i]=0;
    109         c[i].pb(-1);
    110         rep(j,1,r[i])
    111         {
    112             int x=read();
    113             c[i].pb(x);
    114             if(x<a[1]) b[i]++;
    115         }
    116     }
    117     rep(i,1,n) d[i]=d[i-1]+b[i-1]-r[i-1];
    118     rep(i,1,n) d[i]-=r[i];
    119 
    120     build(0,m,1);
    121     while(q--)
    122     {
    123         int x=read(),y=read(),z=read();
    124         if(c[x][y]<a[1]&&z>a[1])
    125         {
    126             b[x]--;
    127             if(x+1<=m) update(0,m,x+1,m,-1,1);
    128         }
    129         if(c[x][y]>a[1]&&z<a[1])
    130         {
    131             b[x]++;
    132             if(x+1<=m) update(0,m,x+1,m,1,1);
    133         }
    134         int tmp=t[1].s;
    135         if(tmp<0) printf("0
    ");
    136          else printf("1
    ");
    137         c[x][y]=z;
    138     }
    139     return 0;
    140 }
  • 相关阅读:
    zookeeper使用场景
    zookeeper安装配置
    hadoop 远程调试
    deep learning笔记
    Sentiment Analysis(1)-Dependency Tree-based Sentiment Classification using CRFs with Hidden Variables
    PRML阅读笔记 introduction
    Python 学习笔记(2)
    python nltk 学习笔记(5) Learning to Classify Text
    python nltk 学习笔记(4) Writing Structured Programs
    python nltk 学习笔记(3) processing raw text
  • 原文地址:https://www.cnblogs.com/myx12345/p/11749157.html
Copyright © 2011-2022 走看看