//============================================================================
// Name : 2380.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <stdio.h>
#include <algorithm>
#include <set>
#include <queue>
#define N 500000
using namespace std;
typedef struct node {
int id1;
int id2;
int value;
} Node;
struct comp {
bool operator()(const Node& a, const Node& b) {
if (a.id1 != b.id1)
return a.id1 > b.id1;
return a.id2 > b.id2;
}
};
int com(const Node& a, const Node& b) {
if (a.id1 != b.id1)
return a.id1 - b.id1;
return a.id2 - b.id2;
}
vector<Node> data;
set<int> sids;
int main() {
int n;
scanf("%d", &n);
Node nd;
for (int i = 0; i < n; i++) {
scanf("%d %d %d", &nd.id2, &nd.id1, &nd.value);
data.push_back(nd);
sids.insert(nd.id2);
}
int* ctid= new int[sids.size()];
int column = 0;
printf("-1");
for (set<int>::iterator it2 = sids.begin(); it2 != sids.end(); ++it2) {
ctid[column++] = *it2;
printf(" %d", *it2);
}
puts("");
priority_queue<Node, vector<Node>, comp> q(data.begin(), data.end());
Node last = q.top();
q.pop();
int rowid = last.id1;
int c = 0;
printf("%d", rowid);
while (!q.empty()) {
Node top = q.top();
q.pop();
if (com(top, last) == 0) {
last.value += top.value;
} else {
if (rowid != last.id1) {
rowid = last.id1;
while (c < column) {
c++;
printf(" 0");
}
c = 0;
puts("");
printf("%d", rowid);
}
int nc = last.id2;
while (ctid[c] < nc) {
c++;
printf(" 0");
}
c++;
printf(" %d", last.value);
last = top;
}
}
if (rowid != last.id1) {
rowid = last.id1;
while (c < column) {
c++;
printf(" 0");
}
c = 0;
puts("");
printf("%d", rowid);
}
int nc = last.id2;
while (ctid[c] < nc) {
c++;
printf(" 0");
}
c++;
printf(" %d", last.value);
while (c < column) {
c++;
printf(" 0");
}
puts("");
return 0;
}
poj2380
最新推荐文章于 2024-04-18 23:25:48 发布