HNOJ Beads

Beads
Time Limit: 1000ms, Special Time Limit:2500ms,Memory Limit:65366KB
Problem description
A game consists of putting beads in boxes. The rules of the game are too complex to describe here, but all you need to know is that keeping track of the number of beans in adjacent boxes are very important to the outcome of the game.
You are asked by a friend to write a program to help him win the game every time. At the start of a game, all boxes are empty.
Input
The first line of the input consists of a single number T, the number of games played. Each game start with a line describing B, P and Q, the number of boxes, put requests and query requests, respectively. Then follows P + Q lines with either P i a, saying a beads are put in box number i,or Q i j, a query request for the number of beads in boxes i through j, inclusive.
Output
For each query request, output the number of beads in boxes a through b, inclusive, that are in the boxes at this point of the game.
Sample Input
1
7 5 3
P 2 1
P 3 3
P 4 7
Q 1 4
P 7 6
Q 4 4
P 6 4
Q 1 7
Sample Output
11
7
21
Judge Tips
0 < T 100 0 < B 100000 0 < P 30000 0 < Q <= 30000 0 <= a <= 100 0 < i <= j <= B Note that boxes are 1-indexed. This is an I/O-heavy problem. For Java programmers, this means that you should use BufferedReader for input reading (not Scanner). It is also bene cial to build all output in a StringBuilder before printing in a single print statement.
Problem Source

IDIOPEN 2011

 

 

题目大意:赤裸裸的树状数组模板啊,但是不会码,只好码线段树了,第一次码线段树,纠结~~囧。。调试了1个小时,囧。。


思路:cover:表示的是如果插入的数在某个区间内,该区间的cover就要相应加上该值。我无限调试在mid用的是线段的那一种情况,所以在分左右子树的时候没有mid+1.囧。。。

 

program:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int sum;
struct node
{
  int a,b,cover;      
}tt[1000000];
void first(int p,int a,int b)
{
   int mid=(a+b)/2;
   tt[p].a=a;
   tt[p].b=b;
   tt[p].cover=0;
   if(a==b)
       return ;
   first(p*2,a,mid);
   first(p*2+1,mid+1,b);
    
}
void insert(int p,int i,int w)
{
     int mid=(tt[p].a+tt[p].b)/2;
    /* if(tt[p].a==a&&tt[p].b==b)
        {
          tt[p].cover++;                    
        }*/
     if(i>=tt[p].a  && i<=tt[p].b )
        {
           tt[p].cover+=w;            
        }
     if(tt[p].a==tt[p].b)
        return;
     if(i<=mid)
        insert(p*2,i,w);
     else if(i>=mid+1)
        insert(p*2+1,i,w);
}
void query(int p,int a,int b )
{
     int mid=(tt[p].a+tt[p].b)/2;
     //cout<<endl<<endl;
     //cout<< "tt[p].a tt[p].b tt[p].cover "<<tt[p].a<<' '<<tt[p].b<<' '<<tt[p].cover<<endl;
     if(tt[p].a==a&&tt[p].b==b)
        {
          sum+=tt[p].cover;//cout<<tt[p].cover<<endl;
          return;
        }
     if(tt[p].a==tt[p].b)////////////
        return;
     //cout<<"a b  "<<a<<' '<<b<<endl;
     //cout<<"mid   "<<mid<<endl;
     if(b<=mid)
        query(p*2,a,b);
     else if(a>=mid+1)///CAOCAOCAO  就是在这里败了,o(╯□╰)o
        query(p*2+1,a,b);
     else
        {
          query(p*2,a,mid);
          query(p*2+1,mid+1,b);               
        } 
          
}
int main()
{
int test;
scanf("%d",&test);
while(test--)
{  
   int B,P,Q;
   scanf("%d%d%d",&B,&P,&Q);
   first(1,1,B);
   char oder;int i,w;
   for(int k=1;k<=P+Q;k++)
   { 
     getchar();
     scanf("%c%d%d",&oder,&i,&w);
     if(oder=='P')
        insert(1,i,w);
     else if(oder=='Q')
        {
          sum=0;
          query(1,i,w);
          printf("%d\n",sum);
        }
   }           
}
//system("pause");
return 0;
}

资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在当今的软件开发领域,自动化构建与发布是提升开发效率和项目质量的关键环节。Jenkins Pipeline作为一种强大的自动化工具,能够有效助力Java项目的快速构建、测试及部署。本文将详细介绍如何利用Jenkins Pipeline实现Java项目的自动化构建与发布。 Jenkins Pipeline简介 Jenkins Pipeline是运行在Jenkins上的一套工作流框架,它将原本分散在单个或多个节点上独立运行的任务串联起来,实现复杂流程的编排与可视化。它是Jenkins 2.X的核心特性之一,推动了Jenkins从持续集成(CI)向持续交付(CD)及DevOps的转变。 创建Pipeline项目 要使用Jenkins Pipeline自动化构建发布Java项目,首先需要创建Pipeline项目。具体步骤如下: 登录Jenkins,点击“新建项”,选择“Pipeline”。 输入项目名称和描述,点击“确定”。 在Pipeline脚本中定义项目字典、发版脚本和预发布脚本。 编写Pipeline脚本 Pipeline脚本是Jenkins Pipeline的核心,用于定义自动化构建和发布的流程。以下是一个简单的Pipeline脚本示例: 在上述脚本中,定义了四个阶段:Checkout、Build、Push package和Deploy/Rollback。每个阶段都可以根据实际需求进行配置和调整。 通过Jenkins Pipeline自动化构建发布Java项目,可以显著提升开发效率和项目质量。借助Pipeline,我们能够轻松实现自动化构建、测试和部署,从而提高项目的整体质量和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值