Last active
March 26, 2017 20:09
-
-
Save Zoha131/62adf0fbbdb5e5de68262519db34361c to your computer and use it in GitHub Desktop.
url of the problem: http://algo.codemarshal.org/contests/diu-122-spr17-termwork/problems/ZC && http://algo.codemarshal.org/contests/diu-122-spr17-termwork/problems/ZD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
int main() | |
{ | |
int t,i; | |
scanf("%d", &t); | |
for(i=1;i<=t;i++) | |
{ | |
long int n_int, q_int, n_arr[500], q_arr_i[100], | |
q_arr_j[100],j,k,l,m,n,greater,smaller; | |
unsigned long long int sum; | |
scanf("%ld %ld", &n_int, &q_int); | |
for(k=0;k<n_int;k++){ | |
scanf("%ld", &n_arr[k]); | |
} | |
for(l=0;l<q_int;l++) | |
{ | |
scanf("%ld %ld", &q_arr_i[l], &q_arr_j[l]); | |
if(q_arr_i[l] > q_arr_j[l]) | |
{ | |
q_arr_i[l] = q_arr_i[l] ^ q_arr_j[l]; | |
q_arr_j[l] = q_arr_i[l] ^ q_arr_j[l]; | |
q_arr_i[l] = q_arr_i[l] ^ q_arr_j[l]; | |
} | |
} | |
printf("Case %d:\n",i); | |
for(j=0;j<q_int;j++) | |
{ | |
sum = 0; | |
for(n=0;n<n_int; n++) | |
{ | |
if(n_arr[n] >= q_arr_i[j] && n_arr[n] <= q_arr_j[j]) | |
{ | |
sum += n_arr[n]; | |
} | |
} | |
printf("%ld %ld %llu\n", q_arr_j[j], q_arr_i[j], sum); | |
} | |
return 0; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
int main() | |
{ | |
int t,i; | |
scanf("%d", &t); | |
for(i=1;i<=t;i++) | |
{ | |
int n_len,q_len,n_arr[500],k,l,o,p,j,sum,q,res_len=0,res_arr[500]; | |
scanf("%d %d", &n_len, &q_len); | |
for(j=0;j<n_len; j++) | |
{ | |
scanf("%d", &n_arr[j]); | |
} | |
for(k=0;k<q_len;k++) | |
{ | |
sum = 0; | |
scanf("%d", &l); | |
if(l==1) | |
{ | |
scanf("%d",&o); | |
res_arr[res_len++] = n_arr[o]; | |
n_arr[o] = 0; | |
} | |
else if(l==2) | |
{ | |
scanf("%d %d", &o,&p); | |
n_arr[o] += p; | |
} | |
else if(l==3) | |
{ | |
scanf("%d %d", &o, &p); | |
for(q=o;q<=p;q++) | |
{ | |
sum += n_arr[q]; | |
} | |
res_arr[res_len++] = sum; | |
} | |
else | |
{ | |
printf("Something went wrong!"); | |
} | |
} | |
printf("Case %d:\n",i); | |
for(k=0;k<res_len;k++) | |
{ | |
printf("%d\n",res_arr[k]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment