Skip to main content

SER11




#include<stdio.h>
    int main()
    {
    long long int t,ss[100001],ww[100002],type,x,tim,i,j,k,mid,poi;
    scanf("%lld",&t);
    poi=1;
    ww[0]=0;
    ss[0]=0;
    for(i=0;i<t;i++)
    {
    scanf("%lld %lld %lld",&type,&x,&tim);
    if(type==1)
    {
    ss[poi]=tim;
    ww[poi]=x+ww[poi-1];
    poi++;
    }
    else if(type==2)
    {
    j=1;
    k=poi-1;
    while(j<=k)
    {
    mid=(j+k)/2;
    if((tim-ss[mid])<x)
    k=mid-1;
    else
    j=mid+1;
    }
    if(mid<0)
    mid=0;
    if(mid>=poi)
    mid=poi-1;
    if((tim-ss[mid])>x)
    mid=mid+1;
    else if((tim - ss[mid])<=x )
    {
    if( mid-1 >=0 && (tim - ss[mid-1])<=x)
    mid=mid-1;
     
    }
    if(mid==0)
    printf("%lld\n",ww[poi-1]-ww[mid]);
    else
    printf("%lld\n",ww[poi-1]-ww[mid-1]);
   
    }
    }
    return 0;
    }

Comments

Popular posts from this blog

SORT 14 #include<stdio.h> int main() {   int a[1001];  int n,i,j,t,swap,temp,k,m,s,r,x=1,ss=1,c=1,f=0;  scanf("%d", &t);  while(t--)  {      swap=0;      scanf("%d %d  %d", &m,&s,&n);          for(i=0; i<n; i++){          scanf("%d", &a[i]);      }      for(i=0; i<n-1; i++){          //temp=i;          for(j=0;j<n-i-1;j++){              //temp=a[j];              if(a[j]>a[j+1]){                   temp=a[j];                   a[j]=a[j+1];                   a[j+1]=temp;                   ...

DS

SORT 3 #include <iostream> using namespace std; void printArr(int arr[], int size) { for(int i=0;i<size;i++) { cout<<arr[i]<<" "; }   cout<<endl; } void sort(int a[],int n) { for(int i=0;i<n-1;i++)     {       for(int j=0;j<n-i-1;j++)       {       if(a[j]>a[j+1])       {       int temp=a[j];         a[j]=a[j+1];         a[j+1]=temp;       }       }       if(i==2)         printArr(a,n);     } } int main() {   int n;   cin>>n;   int a[n];   for(int i=0;i<n;i++)   { cin>>a[i];     }   sort(a,n);   cout<<"Sorted array:";   printArr(a,n); return 0; }
SRM CCC HACKER RANK: Binary string duplication: python import sys s = [0] while len(s) < 1000:     s += [1-x for x in s]           def duplication(s, x):     return s[x]           q = int(input().strip()) for a0 in range(q):     x = int(input().strip())     result = duplication(s,x)     print(result)