zoukankan      html  css  js  c++  java
  • 计蒜客第六场

    非要手打线段树 

    出事了吧……

      1 #include<bits/stdc++.h>
      2 #define cl(a,b) memset(a,b,sizeof(a))
      3 #define debug(x) cerr<<#x<<"=="<<(x)<<endl
      4 using namespace std;
      5 typedef long long ll;
      6 typedef pair<int,int> pii;
      7 
      8 #define ls getid(l,l+r>>1)
      9 #define rs getid((l+r>>1)+1,r)
     10 #define lson l,m,ls
     11 #define rson m+1,r,rs
     12 
     13 typedef long long ll;
     14 
     15 const int maxn = 2e5+10;
     16 
     17 pii p[maxn];
     18 
     19 inline int getid(int x,int y)
     20 {
     21     return x+y|y!=x;
     22 }
     23 
     24 int rm[maxn<<1],col[maxn<<1];
     25 
     26 void pushup(int l,int r,int rt)
     27 {
     28     rm[rt]=min(rm[ls],rm[rs]);
     29 }
     30 
     31 void build(int l,int r,int rt)
     32 {
     33     if(l == r)
     34     {
     35         scanf("%d",&rm[rt]);
     36         return ;
     37     }
     38     int m=l+r>>1;
     39     build(lson);
     40     build(rson);
     41     pushup(l,r,rt);
     42 }
     43 
     44 int query(int L,int R,int l,int r,int rt)
     45 {
     46     if( L<=l && r<=R )
     47     {
     48         return rm[rt];
     49     }
     50     int m=l+r>>1;
     51     int ret = 1e10;
     52     if( L<=m ) ret = min(ret,query(L,R,lson));
     53     if( m+1<=R ) ret = min(ret,query(L,R,rson));
     54     return ret;
     55 }
     56 
     57 int main()
     58 {
     59     int n,m,k;
     60     scanf("%d%d",&n,&k);
     61     build(1,n,1);
     62     scanf("%d",&m);
     63     for(int i=0; i<m; i++)
     64     {
     65         int a,b;
     66         scanf("%d%d",&a,&b);
     67         p[i] = {a,b};
     68     }
     69     int ans=0;
     70     for(int i=0; i<m; i++)
     71     {
     72         for(int j=0; j<i; j++)
     73         {
     74             pii tmpa=p[i];
     75             pii tmpb=p[j];
     76             if(tmpa.first > tmpb.first)
     77             {
     78                 swap(tmpa,tmpb);
     79             }
     80             int tmp=min(tmpa.second,tmpb.second);
     81             tmp=min(tmp,query(tmpa.first,tmpb.first,1,n,1));
     82             if(tmpa.second + tmpb.second - tmp
     83              - tmpa.first + tmpb.first - tmp <= k)
     84             {
     85                 ans++;
     86             }
     87         }
     88     }
     89     printf("%d
    ",ans);
     90     return 0;
     91 }/*
     92 
     93 5 7
     94 4 1 1 3 1
     95 3
     96 1 4
     97 3 1
     98 4 3
     99 
    100 */
  • 相关阅读:
    解决JDBC连接MySQL 8时得异常:java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone.
    洛谷P2604(最大流+最小费用最大流)
    poj2411(状压dp)
    二轮前水题计划
    最近挖的坑
    关于我
    future
    mysql学习笔记
    vue踩坑记
    XSS漏洞学习笔记
  • 原文地址:https://www.cnblogs.com/general10/p/6941936.html
Copyright © 2011-2022 走看看