[分治] 51Nod1472 Codeforces #549F. Yura and Developers
来源:互联网 发布:头影测量软件 编辑:程序博客网 时间:2024/04/25 07:27
分治学傻的我只会无脑分治……
题意就是求满足
注意计数的数组不能每次
#include<cstdio>#include<algorithm>using namespace std;typedef long long LL;const int maxn=300005,maxk=1000005;int n,K,a[maxn],sum[maxn],_max[maxn],m_s[maxn];int cnt_sum[maxk],cnt_ms[maxk],vis1[maxk],vis2[maxk],clk;LL ans;void Solve(int L,int R){ if(L>=R) return; int mid=(L+R)>>1; Solve(L,mid); Solve(mid+1,R); clk++; sum[mid]=_max[mid]=m_s[mid]=0; for(int i=mid+1;i<=R;i++){ _max[i]=max(_max[i-1],a[i]); sum[i]=(sum[i-1]+a[i])%K; m_s[i]=((_max[i]-sum[i])%K+K)%K; if(vis2[m_s[i]]!=clk) vis2[m_s[i]]=clk, cnt_ms[m_s[i]]=0; cnt_ms[m_s[i]]++; } for(int i=mid,sumL=0,maxL=0,p=mid;i>=L;i--){ maxL=max(maxL,a[i]); sumL=(sumL+a[i])%K; while(p<R&&_max[p+1]<=maxL){ p++; cnt_ms[m_s[p]]--; if(vis1[sum[p]]!=clk) vis1[sum[p]]=clk, cnt_sum[sum[p]]=0; cnt_sum[sum[p]]++; } int t1=((maxL-sumL)%K+K)%K, t2=sumL; if(vis1[t1]==clk) ans+=cnt_sum[t1]; if(vis2[t2]==clk) ans+=cnt_ms[t2]; } }int main(){ scanf("%d%d",&n,&K); for(int i=1;i<=n;i++) scanf("%d",&a[i]); Solve(1,n); printf("%I64d\n",ans); return 0; }
阅读全文
0 0
- [分治] 51Nod1472 Codeforces #549F. Yura and Developers
- [CF549F/51nod1472]Yura and Developers
- Codeforces 549F Yura and Developers
- codeforces-549F-Yura and Developers
- CodeForces 549F Yura and Developers
- 【CF549F】Yura and Developers
- Yura and Developers
- Codeforces 526F 分治
- 【codeforces】660F. Bear and Bowling 4【分治+维护凸壳】
- CodeForces 526F Pudding Monsters (分治)
- Codeforces 868F 分治优化Dp
- [51nod1472/CF549F]取余最大值
- Codeforces 868F (Codeforces Round #438 F) Yet Another Minimization Problem DP+分治
- Codeforces 611F New Year and Cleaning
- CodeForces 589F Gourmet and Banquet 题解
- Codeforces 628F Bear and Fair Set
- Codeforces 659F Polycarp and Hay【BFS】
- Codeforces 660F:Bear and Bowling 4
- PL/SQL Developer使用技巧、快捷键
- 【智安仕】轮胎升级技术分享
- 欢迎参加2017中国卫星应用大会!
- webview设置paddingbottom无效,通过js给android控件WebView设padding
- Win10系统下深度学习框架Keras的安装与搭建
- [分治] 51Nod1472 Codeforces #549F. Yura and Developers
- springmvc
- Maven学习总结
- 操作系统学习_Linux0.12_as汇编
- CCF CSP认证考试历年真题 日期计算 C语言实现
- 喜大普奔!程序员已当选最佳国民女婿
- python unicode转str
- singleCall单来源调用解析及实现
- Manifest merger failed :