zoukankan      html  css  js  c++  java
  • [CF1042D] Petya and Array

    题面

    题解

    这道题目到底叫什么好呢??

    史上最短CDQ分治题

    记一个前缀和,然后CDQ分治即可。

    代码

    #include<cstdio>
    #include<algorithm>
    #define RG register
    
    inline long long read()
    {
    	long long data = 0, w = 1;
    	char ch = getchar();
    	while(ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    	if(ch == '-') w = -1, ch = getchar();
    	while(ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
    	return data*w;
    }
    
    const int maxn(2e5 + 10);
    int n;
    long long sum[maxn], t, ans;
    
    void Div(long long *beg, long long *end)
    {
    	if(end - beg <= 1) return;
    	long long *mid = beg + ((end - beg) >> 1);
    	Div(beg, mid); Div(mid, end);
    
    	for(long long *i = beg, *j = mid; i != mid; ++i, ans += j - mid)
    		while(j != end && (*j) < t + (*i)) ++j;
    	std::inplace_merge(beg, mid, end);
    }
    
    int main()
    {
    	n = read(); t = read();
    	for(RG int i = 1; i <= n; i++) sum[i] = sum[i - 1] + read();
    	Div(sum, sum + n + 1); printf("%lld
    ", ans);
    	return 0;
    }
    
  • 相关阅读:
    反射和内置方法重写
    封装
    接口与抽象类 、多态
    面向对象--继承和组合
    python对象
    模块导入
    python序列化模块
    time random sys os 模块
    python re模块和collections
    python各种推导式
  • 原文地址:https://www.cnblogs.com/cj-xxz/p/9811806.html
Copyright © 2011-2022 走看看