Pagini recente » Cod sursa (job #2628010) | Cod sursa (job #2978848) | Cod sursa (job #2388757) | Cod sursa (job #1235479) | Cod sursa (job #239656)
Cod sursa(job #239656)
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <assert.h>
#define PB push_back
#define ALL(x) x.begin(),x.end()
using namespace std;
struct xyz
{
int x,y,z;
};
int n,m,ind;
vector <int> sol;
vector <xyz> a;
bool operator< (const xyz &a, const xyz &b)
{
return a.x<b.x || a.x==b.x && a.y<b.y;
}
void solve()
{
sol.resize(n+1);
for (int q=m-1;q>=0;--q)
{
sol[a[q].x]=a[q].z;
for (int w=a[q].x+1;w<=a[q].y;++w) sol[a[q].x]-=sol[w];
}
}
void change()
{
sort(ALL(a));
for (int q=1;q<m;++q)
while (q<m && a[q].x==a[q-1].x && a[q].y==a[q-1].y)
{
--m;
a.erase(a.begin()+q);
}
bool found=true;
while (found)
{
found=false;
int limit=m;
for (int q=1;q<limit;++q)
if (q<limit && a[q].x==a[q-1].x)
{
found=true;
xyz aux=a[q];
aux.x=a[q-1].y+1;
aux.z-=a[q-1].z;
/*a.erase(a.begin()+q);
a.PB(aux);*/
a[q]=aux;
//--limit;
break;
}
if (found) sort(ALL(a));
}
}
int main()
{
FILE* fin=fopen("reconst.in","r");
fscanf(fin,"%d%d\n",&n,&m);
for (int q=1;q<=m;++q)
{
int x,y,z;
fscanf(fin,"%d%d%d",&x,&y,&z);
xyz aux;
aux.x=x; aux.y=y; aux.z=z;
a.PB(aux);
}
fclose(fin);
change();
solve();
FILE* fout=fopen("reconst.out","w");
for (int q=1;q<=n;++q) fprintf(fout,"%d ",sol[q]);
fclose(fout);
return 0;
}