Cod sursa(job #111689)

Utilizator MocanuCalinMocanu calin MocanuCalin Data 1 decembrie 2007 18:00:29
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <fstream.h>

int main(){
	ifstream in("datorii.in");
	ofstream out("datorii.out");
	
	long long n,m,i,x,y,z,t,j,ts,td;
	ts=-1;
	td=-1;
	in>>n;
	in>>m;
	long long a[n];
	for(i=0;i<n;i++)
		in>>a[i];
	for(i=0;i<m;i++){
		in>>x;
		in>>y;
		in>>z;
		if(x==1){

			if(y<=ts){
				if(z>ts){
					if(z<td){
						for(j=ts-1;j<y;j++)
							t-=a[j];
						for(j=z-1;j<td;j++)
							t-=a[j];
						ts=y;
						td=z;
						out<<t;
					} else {
						for(j=ts-1;j<y;j++)
							t-=a[j];
						for(j=td-1;j<z;j++)
							t+=a[j];
						ts=y;
						td=z;
						out<<t;
					} 
				} else {	t=0;
					for(j=y-1;j<z;j++)
						t+=a[j];
					ts=y;
					td=z;
					out<<t;
					}
			} else {
				if(z>ts){
					if(z<td){
						for(j=y-1;j<ts;j++)
							t+=a[j];
						for(j=z-1;j<td;j++)
							t-=a[j];
						ts=y;
						td=z;
						out<<t;
					} else {
						for(j=y-1;j<ts;j++)
							t+=a[j];
						for(j=td-1;j<z;j++)
							t+=a[j];
						ts=y;
						td=z;
						out<<t;
					} 
				} else {	t=0;
					for(j=y-1;j<z;j++)
						t+=a[j];
					ts=y;
					td=z;
					out<<t;
					}
			}



		} else {
			a[y-1]-=z;
			if(y>=ts)
				if(y<=td)
					t-=z;
		}
	}
	out.close();
	in.close();
	return 0;
}