CODECHEF Sereja and Commands
来源:互联网 发布:学生怒骂日本记者知乎 编辑:程序博客网 时间:2024/05/22 11:59
题目链接:https://www.codechef.com/SEPT17/problems/SEACO
树状数组,倒着处理
因为数字更新可能为负,所以取模要注意
贴代码
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;const int maxn=100005,P=1000000007;int b[maxn],c[maxn];int n,m,Q;struct rc{ int t,l,r;}a[maxn];int lowbit(int x){ return x&(-x);}void data_1(int x,int y){ for (int i=x;i<=m;i+=lowbit(i))b[i]=(ll(b[i])+ll(y)+ll(P))%ll(P);}void data_2(int x,int y){ for (int i=x;i<=n;i+=lowbit(i))c[i]=(ll(c[i])+ll(y)+ll(P))%ll(P);}int query_1(int x){ int s=0; for (int i=x;i>=1;i-=lowbit(i))s=(ll(s)+ll(b[i])+ll(P))%ll(P); return s;}int query_2(int x){ int s=0; for (int i=x;i>=1;i-=lowbit(i))s=(ll(s)+ll(c[i])+ll(P))%ll(P); return s;}int main(){// freopen("5.in","r",stdin);// freopen("5.out","w",stdout); scanf("%d",&Q); while (Q--){ scanf("%d%d",&n,&m); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); for (int i=1;i<=m;i++)scanf("%d%d%d",&a[i].t,&a[i].l,&a[i].r); for (int i=m;i>=1;i--){ if (a[i].t==1){ int x=query_1(i)+1; data_2(a[i].l,x);data_2(a[i].r+1,-x); }else{ int x=query_1(i)+1; data_1(a[i].l,x);data_1(a[i].r+1,-x); } } for (int i=1;i<=n;i++)printf("%d ",query_2(i)); printf("\n"); } return 0;}
【写的有漏洞的,欢迎路过大神吐槽】
2017/09/11 19:38:13
Ending.
阅读全文
0 0
- CODECHEF Sereja and Commands
- 【codechef】Sereja and Votes(模拟)
- [计数 补集转换][阈值] Codechef SEAARC.Sereja and Arcs
- CodeChef:Sereja and Tree 2(树形dp)
- 【codechef】Nikhil and Commands(字符串删减,分类)
- Codechef June Challenge 2014 #Sereja and Arcs -- 容斥 + 阈值 + 树状数组
- B. Sereja and Array
- Sereja and Bottles
- Sereja and Bottles
- A. Sereja and Bottles
- B. Sereja and Suffixes
- CF380A Sereja and Prefixes
- A. Sereja and Dima
- Sereja and Stairs
- B. Sereja and Stairs
- Sereja and Stairs
- Sereja and Dima
- B. Sereja and Contests
- 安卓EditText输入时自动编号
- 基于Swift的iOS应用程序开发:以Base64字符串形式上传文件——从iOS选择文件并上传
- Java 静态语句块、语句块、构造函数执行顺序
- Android 开发常用的adb命令
- Android Fragment接口传值
- CODECHEF Sereja and Commands
- javaweb学习总结(四)——Http协议
- 数字签名(2):DSA
- Hashmap and Java.io PrintWriter
- Python enumerate
- uva 12168
- 水池数目
- [数据结构]字符串匹配——朴素算法
- BZOJ2301:[HAOI2011]Problem b