1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <algorithm> #include <utility> #include <vector> #include <istream> #include <map> #include <cmath> #include <stack> #include <set> #include <queue> #include <cstring> #include <string> #include <fstream> #define ll long long #define maxn 300005 #define mdl 1000000007 #define clr(a,n) for(int i=0;i<n;i++)a[i]=0 #define cfast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pll pair<ll,ll> #define pii pair<int,int> #define inc(i,a,n) for(int i=a;i<n;i++) #define vset(a,n,m) for(int i=0;i<n;i++)a[i]=m; #define endl '\n' #define pi 3.141592657 using namespace std; ll gcd(ll a, ll b) { if (a < b)swap(a, b); if (b == 0)return a; return gcd(b, a % b); } ll cpow(ll x, ll n) { ll ans = 1; while (n > 0) { if (n & 1) ans = (ans * x) % mdl; x = (x * x) % mdl; n >>= 1; } return ans; } ll getpos(int p, ll n) { return n / cpow(10, p - 1) % 10; } ll getwei(ll n) { int res = 0; while (n) { res++; n /= 10; } return res; }
struct tr { int a , b, m,num; friend bool operator<(tr t1, tr t2) { return t1.a < t2.a; } }trs[maxn]; struct sg { int a, b,num; friend bool operator<(sg s1, sg s2) { if (s1.a == s2.a) { return s1.b > s2.b; } return s1.a < s2.a; } }; vector<tr> sm[maxn]; vector<sg> sgs; map<int,int> has; int ansl[maxn], ansr[maxn]; int main() { cfast; int t; cin >> t; while (t--) { int n; cin >> n; has.clear(); int xb = 1; inc(i, 0, n) { cin >> trs[i].a >> trs[i].b >> trs[i].m; trs[i].num = i; int ad = trs[i].a + trs[i].b - trs[i].m; if (has[ad] == 0) { has[ad] = xb++; } sm[has[ad]].push_back(trs[i]); } ll ans = 0; for (int i = 1; i < xb; i++) { sgs.clear(); int mi = 1e9; inc(j, 0, sm[i].size()) { sg s = { max(0,sm[i][j].a - sm[i][j].m),sm[i][j].a - max(0,sm[i][j].m - sm[i][j].b),sm[i][j].num }; sgs.push_back(s); } sort(sgs.begin(), sgs.end()); for (int j = sgs.size() - 1; j >= 0; j--) { if (sgs[j].b < mi) { ans++; mi = sgs[j].a; } ansl[sgs[j].num] = trs[sgs[j].num].a-mi; ansr[sgs[j].num] = trs[sgs[j].num].m-ansl[sgs[j].num]; } } cout << ans << endl; inc(i, 0, n) { cout << ansl[i] << " "<<ansr[i] << endl; } inc(i, 1, xb+1)sm[i].clear(); } }
|