2019nc#9

 

题号标题已通过代码题解/讨论通过率团队的状态
A The power of Fibonacci 点击查看 进入讨论 69/227 未通过
B Quadratic equation 点击查看 高次剩余 391/888 未通过
C Inversions of all permutations 点击查看 进入讨论 28/61 未通过
D Knapsack Cryptosystem 点击查看 进入讨论 606/2251  通过
E All men are brothers 点击查看 进入讨论 425/1117  通过
F Birthday Reminders 点击查看 进入讨论 5/11 未通过
G Checkers 点击查看 进入讨论 0/15 未通过
H Cutting Bamboos 点击查看 二分,主席树 187/834  通过
I KM and M 点击查看 进入讨论 19/296 未通过
J Symmetrical Painting 点击查看 进入讨论 227/930  通过

H Cutting Bamboos

这道题用主席树过的,记录下区间权值。

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include  <iterator>
#include  <iostream>
#include   <cstring>
#include   <cstdlib>
#include   <iomanip>
#include    <bitset>
#include    <cctype>
#include    <cstdio>
#include    <string>
#include    <vector>
#include     <stack>
#include     <cmath>
#include     <queue>
#include      <list>
#include       <map>
#include       <set>
#include   <cassert>
#include <unordered_map>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a)
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+7;
 
template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
/**********showtime************/
 
            const int N = 2e5 + 5, M = 4e6 + 5;//M为节点个数,为Q*log(N)
            int root[N], lson[M], rson[M], value[M], tot = 0;
            ll sum[M];
            const double eps = 1e-7;
            //建树
            void build(int &x, int l, int r) {
                x = ++tot;
                value[x] = 0;
                sum[x] = 0;
                if(l == r) {
                    return ;
                }
                int m = (l+r) >> 1;
                build(lson[x], l, m);
                build(rson[x], m+1, r);
                value[x] = value[lson[x]] + value[rson[x]];
            }
            // 将某个历史版本p位置的值加v
            void update(int old, int &x, int p, int v, int l, int r) {
                x = ++tot;
                lson[x] = lson[old], rson[x] = rson[old], value[x] = value[old] + v, sum[x] = sum[old] + p;
                if(l == r) return ;
                int m = (l+r) >> 1;
                if(p <= m) update(lson[x], lson[x], p, v, l, m);
                else update(rson[x], rson[x], p, v, m+1, r);
            }
            //访问某个历史版本L到R的区间和
            int query(int L, int R, int x, int l, int r) {
                if(L <= l && r <= R) return value[x];
                int m = (l+r) >> 1, ans = 0;
                if(L <= m) ans += query(L, R, lson[x], l, m);
                if(R > m) ans += query(L, R, rson[x], m+1, r);
                return ans;
            }
            ll query2(int L, int R, int x, int l, int r) {
                if(L <= l && r <= R) return sum[x];
                int m = (l+r) >> 1;
                ll ans = 0;
                if(L <= m) ans += query2(L, R, lson[x], l, m);
                if(R > m) ans += query2(L, R, rson[x], m+1, r);
                return ans;
            }
            const int maxn = 2e5+9;
            ll pre[maxn], a[maxn];
            double cal(double val, int L, int R) {
                int hi = floor(val);
                int cnt = query(0, hi, root[R], 0, 100000) - query(0, hi, root[L-1], 0, 100000);
                double ss =  (R - L + 1 - cnt) * val;
                ss += 1.0*query2(0, hi,root[R], 0, 100000) - query2(0, hi, root[L-1], 0, 100000);
                return ss;
            }
int main(){
            int n,m;
            scanf("%d%d", &n, &m);
            build(root[0], 0, 100000);
            for(int i=1; i<=n; i++) {
                scanf("%lld", &a[i]), pre[i] = pre[i-1] + a[i];
                update(root[i-1], root[i], a[i], 1, 0, 100000);
            }
            while(m--) {
                int L, R, x, y;
                scanf("%d%d%d%d", &L, &R, &x, &y);
                ll ss = pre[R] - pre[L-1];
                double nd = ss*1.0 / y *(y - x);
                double le = 0, ri = 1000000005, res = 0;
                //debug(nd);
                while(le + eps < ri) {
                    double mid = (le + ri) / 2;
                    if(cal(mid, L, R) <= nd) le = mid, res = mid;
                    else ri = mid;
                }
                printf("%.10f\n", res);
            }
            return 0;
}
View Code

 

J Symmetrical Painting

题意:

有n个矩形,宽度都为1,排列在坐标轴上,问消去一些矩形的一部分,使得原来的图形上下对称。这个对称图形最大可能面积。

思路:

有点类似扫描线的做法。

/*
* @Author: chenkexing
* @Date:   2019-08-16 15:34:14
* @Last Modified by:   chenkexing
* @Last Modified time: 2019-08-16 15:41:12
*/

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include  <iterator>
#include  <iostream>
#include   <cstring>
#include   <cstdlib>
#include   <iomanip>
#include    <bitset>
#include    <cctype>
#include    <cstdio>
#include    <string>
#include    <vector>
#include     <stack>
#include     <cmath>
#include     <queue>
#include      <list>
#include       <map>
#include       <set>
#include   <cassert>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}

/**********showtime************/
            const int maxn = 300009;
            pii a[maxn * 3];

int main(){
            int n;  
            scanf("%d", &n);
            int tot = 0;
            for(int i=1; i<=n; i++) {
                int le,ri;
                scanf("%d%d", &le, &ri);
                // 在底,中点,高上有可能取到极值。
                a[++tot] = pii(2*le, 1);
                a[++tot] = pii(le + ri, -2);
                a[++tot] = pii(2*ri, 1);
            }
            sort(a+1, a+1+tot);
            ll ans = 0, sum = 0;
            ll cnt = a[1].se;
            for(int i=2; i<=tot; i++) {
                sum += cnt * (a[i].fi - a[i-1].fi);
                ans = max(ans, sum);
                cnt += a[i].se;
            }
            printf("%lld\n", ans);
            return 0;
}
View Code

 

posted @ 2019-08-16 15:50  ckxkexing  阅读(189)  评论(0编辑  收藏  举报