CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(easy) » Gravel

Gravel

Problem code: SPREAD

  • Submit
  • All Submissions

All submissions for this problem are available.

Bob has n heap(s) of gravel (initially there are exactly c piece(s) in each). He wants to do m operation(s) with that heaps, each maybe:

  • adding pieces of gravel onto the heaps from u to v, exactly k pieces for each,
  • or querying "how many pieces of gravel are there in the heap p now?".

Request

Help Bob do operations of the second type.

Input

  • The first line contains the integers n,m,c, respectively.
  • m following lines, each forms:
    • S u v k to describe an operation of the first type.
    • Q p to describe an operation of the second type.

  • (Each integer on a same line, or between the characters S, Q and the integers is separated by at least one space character)

Output

For each operation of the second type, output (on a single line) an integer answering to the respective query (follows the respective Input order).

Example

Input:
7 5 0
Q 7
S 1 7 1
Q 3
S 1 3 1
Q 3
Output:
0
1
2

Limitations

  • 0<n?106
  • 0<m?250 000
  • 0<u?v?n
  • 0?c,k?109
  • 0<p?n

Author: anhdq
Date Added: 5-05-2010
Time Limit: 2 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, C, C99 strict, CLOJ, CPP 4.0.0-8, CPP 4.3.2, CS2, D, F#, FORT, GO, ICON, JAR, JAVA, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PYTH, PYTH 3.1.2, RUBY, SCM guile, SCM qobi, ST, TCL


  • Submit

Comments

  • Login or Register to post a comment.

Why am i getting wrong

singh_637 @ 12 Apr 2011 11:31 PM

Why am i getting wrong answer?

Could you please give me more test cases?

 

#include<stdio.h>

long long int a[1000050]={0};
long long int result,result1,result2,sum=0;

void scan(char str[])
{
int i=0,m;
result=0;
result1=0;
result2=0;
sum=0;
i=2;
while(str[i]!='')
{

switch(str[i])
{
case '0': m=0; break;
case '1': m=1; break;
case '2': m=2; break;
case '3': m=3; break;
case '4': m=4; break;
case '5': m=5; break;
case '6': m=6; break;
case '7': m=7; break;
case '8': m=8; break;
case '9': m=9; break;
}
if(str[i+1]==' ' || str[i+1]=='')
{

sum=sum*10+m;
result=sum;
i++;
sum=0;
goto X;
}
else
{
sum=sum*10+m;
goto Y;
}
X:while(str[i]!='')
{
switch(str[i])
{
case '0': m=0; break;
case '1': m=1; break;
case '2': m=2; break;
case '3': m=3; break;
case '4': m=4; break;
case '5': m=5; break;
case '6': m=6; break;
case '7': m=7; break;
case '8': m=8; break;
case '9': m=9; break;
}
if(str[i+1]==' ')
{
sum=sum*10+m;
result1=sum;
i+=2;
sum=0;
goto S;
}
else
{
sum=sum*10+m;
goto Z;
}
S:while(str[i]!='')
{
switch(str[i])
{
case '0': m=0; break;
case '1': m=1; break;
case '2': m=2; break;
case '3': m=3; break;
case '4': m=4; break;
case '5': m=5; break;
case '6': m=6; break;
case '7': m=7; break;
case '8': m=8; break;
case '9': m=9; break;
}
if(str[i+1]=='')
{
sum=sum*10+m;
result2=sum;
i++;
break;
}
else
{
sum=sum*10+m;
goto T;
}
T:i++;
}
Z:i++;
}
Y:i++;
}
}
int main()
{
long long int n,test;
long long int c;

int j;
char str[80]="";
scanf("%lld%lld%lld",&n,&test,&c);
for(j=0; j<=n; j++)
a[j]=c;
while(test--)
{
printf("n");
fflush(stdin);
gets(str);
scan(str);
if(str[0]=='Q')
printf("%lld",a[result]);
else
{
for(j=result; j<=result1;    j++)
{
a[j]+=result2;
}
}
}

return 0;
}

This program is producing

singh_637 @ 13 Apr 2011 11:10 PM

This program is producing correct output in my computer but it is showing wrong output on this website.

Please tell me why?

 

#include<stdio.h>
#define max 1000050
long long a[max];

long long int result,result1,result2,sum=0;

void scan(char str[])
{
int i=0,m,flag=0;
result=0;
result1=0;
result2=0;
sum=0;
i=2;
while(str[i]!='')
{

switch(str[i])
{
case '0': m=0; break;
case '1': m=1; break;
case '2': m=2; break;
case '3': m=3; break;
case '4': m=4; break;
case '5': m=5; break;
case '6': m=6; break;
case '7': m=7; break;
case '8': m=8; break;
case '9': m=9; break;
}
if(str[i+1]==' ' || str[i+1]=='')
{

sum=sum*10+m;
result=sum;
i++;
flag=0;
sum=0;
goto X;
}
else
{
sum=sum*10+m;
goto Y;
}
X:while(str[i]!='')
{
if(flag==0)
{
i++;
flag=1;
}
switch(str[i])
{
case '0': m=0; break;
case '1': m=1; break;
case '2': m=2; break;
case '3': m=3; break;
case '4': m=4; break;
case '5': m=5; break;
case '6': m=6; break;
case '7': m=7; break;
case '8': m=8; break;
case '9': m=9; break;
}
if(str[i+1]==' ')
{
sum=sum*10+m;
result1=sum;
i+=2;
sum=0;
goto S;
}
else
{
sum=sum*10+m;
goto Z;
}
S:while(str[i]!='')
{
switch(str[i])
{
case '0': m=0; break;
case '1': m=1; break;
case '2': m=2; break;
case '3': m=3; break;
case '4': m=4; break;
case '5': m=5; break;
case '6': m=6; break;
case '7': m=7; break;
case '8': m=8; break;
case '9': m=9; break;
}
if(str[i+1]=='')
{
sum=sum*10+m;
result2=sum;
i++;
break;
}
else
{
sum=sum*10+m;
goto T;
}
T:i++;
}
Z:i++;
}
Y:i++;
}
}

int main()
{
long long int n,test;
long long int c;

int j;

scanf("%lld%lld%lld",&n,&test,&c);
for(j=0; j<=n; j++)
a[j]=c;
while(test--)
{
char str[80]="";

fflush(stdin);

gets(str);
scan(str);
if(str[0]=='Q')
printf("%lld",a[result]);
else
{
for(j=result; j<=result1;    j++)
{
a[j]+=result2;
}
}
}

return 0;
}

I am getting runtime error

sakuag333 @ 18 Apr 2011 12:31 AM

I am getting runtime error again and again.

i am using segment tree.

the code is running fine on my system with even n=100000.

@sakuag333 ur getting runtime

KK123 @ 19 Jul 2011 01:01 AM
@sakuag333 ur getting runtime error bcoz may be ur using smaller array.... try it again increasing the size of the array...

Hi I am getting correct

suneelprakash @ 19 Jan 2012 01:16 PM
Hi I am getting correct output but time limit exceeded But still i can see some submissions where aircube 178.6M 41.97 JAVA View Solution 41.97 is timelimit How can i know the time taken for it.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
  • If you are still having problems, see a sample solution here.

CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com