Cod sursa(job #317864)

Utilizator iulia609fara nume iulia609 Data 25 mai 2009 18:48:57
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include<stdio.h>
#include<math.h>
#define dim 15001
using namespace std;

int b,c,i,v[dim],n,poztemp;

int main()
 {int m,a,x,sum,st,dr,poz,s1,s2;
 
  FILE*f=fopen("datorii.in","r");
  FILE*g=fopen("datorii.out","w");
  
  fscanf(f,"%d%d",&n,&m);
  
  sum=0;
  for(i=1;i<=n;i++)
	  {fscanf(f,"%d",&x);
	   //sum+=x;
	   v[i]=x;
	  }
  
  for(i=1;i<=m;i++)
	  {fscanf(f,"%d%d%d",&a,&b,&c);
if(a==1) 
{ st=b;dr=c;x=1;
  poz=s1=poztemp=0;
  while(dr>0)
	{ s1+=v[dr];
	  while(dr&pow(2,poz)==0) 
		  poz++;
	  poztemp=poz-poztemp;
	  x*=pow(2,poztemp);
	  dr-=x;
	  poztemp=poz;
	  //poz++;
	}
  st--;
  s2=poz=0;
  while(st>0) 
	{ s2+=v[st];
	  while(st&pow(2,poz)==0) 
		  poz++;
	  poztemp=poz-poztemp;
	  x*=pow(2,poztemp);
	  st-=x;
	  poztemp=poz;
	  //poz++;
	}
  fprintf(g,"%d\n",s1-s2);
 }
else 
//{poz=0;
  //while(b<=n)
	 v[b]-=c;
	 /* while(b&pow(2,poz)==0) 
		poz++;
	  b+=pow(2,poz);
	  poz++;
	 }
 }*/
	   }
  fclose(f);
  fclose(g);
  return 0;
 }