QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#157662 | #7105. Pixel Art | ucup-team088# | AC ✓ | 476ms | 38392kb | C++17 | 10.2kb | 2023-09-02 15:40:19 | 2023-09-02 15:40:19 |
Judging History
你现在查看的是测评时间为 2023-09-02 15:40:19 的历史记录
- [2023-09-04 04:30:22]
- hack成功,自动添加数据
- (//qoj.ac/hack/364)
- [2023-09-02 15:40:19]
- 提交
answer
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<chrono>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
//ll mod = 1;
constexpr ll mod = 998244353;
//constexpr ll mod = 1000000007;
const int mod17 = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
using ld = double;
typedef pair<ld, ld> LDP;
const ld eps = 1e-10;
const ld pi = acosl(-1.0);
template<typename T>
void chmin(T& a, T b) {
a = min(a, b);
}
template<typename T>
void chmax(T& a, T b) {
a = max(a, b);
}
template<typename T>
vector<T> vmerge(vector<T>& a, vector<T>& b) {
vector<T> res;
int ida = 0, idb = 0;
while (ida < a.size() || idb < b.size()) {
if (idb == b.size()) {
res.push_back(a[ida]); ida++;
}
else if (ida == a.size()) {
res.push_back(b[idb]); idb++;
}
else {
if (a[ida] < b[idb]) {
res.push_back(a[ida]); ida++;
}
else {
res.push_back(b[idb]); idb++;
}
}
}
return res;
}
template<typename T>
void cinarray(vector<T>& v) {
rep(i, v.size())cin >> v[i];
}
template<typename T>
void coutarray(vector<T>& v) {
rep(i, v.size()) {
if (i > 0)cout << " "; cout << v[i];
}
cout << "\n";
}
ll mod_pow(ll x, ll n, ll m = mod) {
if (n < 0) {
ll res = mod_pow(x, -n, m);
return mod_pow(res, m - 2, m);
}
if (abs(x) >= m)x %= m;
if (x < 0)x += m;
//if (x == 0)return 0;
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
//mod should be <2^31
struct modint {
int n;
modint() :n(0) { ; }
modint(ll m) {
if (m < 0 || mod <= m) {
m %= mod; if (m < 0)m += mod;
}
n = m;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
bool operator<(modint a, modint b) { return a.n < b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= (int)mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += (int)mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[a - b];
}
ll gcd(ll a, ll b) {
a = abs(a); b = abs(b);
if (a < b)swap(a, b);
while (b) {
ll r = a % b; a = b; b = r;
}
return a;
}
template<typename T>
void addv(vector<T>& v, int loc, T val) {
if (loc >= v.size())v.resize(loc + 1, 0);
v[loc] += val;
}
/*const int mn = 2000005;
bool isp[mn];
vector<int> ps;
void init() {
fill(isp + 2, isp + mn, true);
for (int i = 2; i < mn; i++) {
if (!isp[i])continue;
ps.push_back(i);
for (int j = 2 * i; j < mn; j += i) {
isp[j] = false;
}
}
}*/
//[,val)
template<typename T>
auto prev_itr(set<T>& st, T val) {
auto res = st.lower_bound(val);
if (res == st.begin())return st.end();
res--; return res;
}
//[val,)
template<typename T>
auto next_itr(set<T>& st, T val) {
auto res = st.lower_bound(val);
return res;
}
using mP = pair<modint, modint>;
mP operator+(mP a, mP b) {
return { a.first + b.first,a.second + b.second };
}
mP operator+=(mP& a, mP b) {
a = a + b; return a;
}
mP operator-(mP a, mP b) {
return { a.first - b.first,a.second - b.second };
}
mP operator-=(mP& a, mP b) {
a = a - b; return a;
}
LP operator+(LP a, LP b) {
return { a.first + b.first,a.second + b.second };
}
LP operator+=(LP& a, LP b) {
a = a + b; return a;
}
LP operator-(LP a, LP b) {
return { a.first - b.first,a.second - b.second };
}
LP operator-=(LP& a, LP b) {
a = a - b; return a;
}
mt19937 mt(time(0));
const string drul = "DRUL";
string senw = "SENW";
//DRUL,or SENW
//int dx[4] = { 1,0,-1,0 };
//int dy[4] = { 0,1,0,-1 };
//------------------------------------
struct uf {
private:
vector<int> par, ran;
public:
uf(int n) {
par.resize(n, 0);
ran.resize(n, 0);
rep(i, n) {
par[i] = i;
}
}
int find(int x) {
if (par[x] == x)return x;
else return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)return;
if (ran[x] < ran[y]) {
par[x] = y;
}
else {
par[y] = x;
if (ran[x] == ran[y])ran[x]++;
}
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
using ar = array<int, 3>;
vector<ar> vy[1 << 17];
void solve() {
int n, m, k; cin >> n >> m >> k;
vector<vector<ar>> vx(n);
//vector<vector<ar>> vy(m);
vector<int> ys;
rep(i, k) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1--; y1--; x2--; y2--;
ys.push_back(y1);
ys.push_back(y2);
if (x1 == x2) {
vx[x1].push_back({ y1,y2 + 1,i });
}
else {
vy[y1].push_back({ x1,x2 + 1,i });
}
}
sort(all(ys));
ys.erase(unique(all(ys)), ys.end());
rep(i, n)sort(all(vx[i]));
for (int j : ys)sort(all(vy[j]));
vector<vector<int>> addids(n);
rep(i, n)for (auto a : vx[i]) {
addids[i].push_back(a[2]);
}
for (int i : ys)for (auto a : vy[i]) {
addids[a[0]].push_back(a[2]);
}
vector<vector<P>> addps(n);
for(int j:ys){
int loc = 0;
for (auto a1 : vy[j]) {
while (loc < vy[j + 1].size() && vy[j + 1][loc][1] <= a1[0])loc++;
for (int k = loc; k < vy[j + 1].size(); k++) {
if (vy[j + 1][k][0] >= a1[1])break;
int le = max(vy[j + 1][k][0], a1[0]);
addps[le].push_back({ a1[2],vy[j + 1][k][2] });
}
}
}
for(int j:ys){
rep(i, (int)vy[j].size() - 1) {
if (vy[j][i][1] == vy[j][i + 1][0]) {
addps[vy[j][i + 1][0]].push_back({ vy[j][i][2],vy[j][i + 1][2] });
}
}
}
rep(i, n - 1) {
int loc = 0;
for (auto a1 : vx[i]) {
while (loc < vx[i + 1].size() && vx[i + 1][loc][1] <= a1[0])loc++;
for (int k = loc; k < vx[i + 1].size(); k++) {
if (vx[i + 1][k][0] >= a1[1])break;
int le = max(vx[i + 1][k][0], a1[0]);
addps[i + 1].push_back({ a1[2],vx[i + 1][k][2] });
}
}
}
rep(i, n) {
rep(j, (int)vx[i].size() - 1) {
if (vx[i][j][1] == vx[i][j + 1][0]) {
addps[i].push_back({ vx[i][j][2],vx[i][j + 1][2] });
}
}
}
vector<vector<P>> adp(n);
vector<vector<P>> delp(n + 1);
for(int j:ys){
for (auto a : vy[j]) {
adp[a[0]].push_back({ j,a[2] });
delp[a[1]].push_back({ j,a[2] });
}
}
set<P> stp;
rep(i, n) {
for (auto p : delp[i]) {
stp.erase(p);
}
for (auto p : adp[i]) {
stp.insert(p);
}
rep(j, vx[i].size()) {
int le = vx[i][j][0];
int ri = vx[i][j][1];
int id = vx[i][j][2];
auto itr = prev_itr(stp, { le,-1 });
if (itr != stp.end()&&(*itr).first==le-1) {
addps[i].push_back({ (*itr).second,id });
}
itr = next_itr(stp, { ri,-1 });
if (itr != stp.end()&&(*itr).first==ri) {
addps[i].push_back({ (*itr).second,id });
}
}
}
vector<ar> adyp;
vector<ar> delyp;
rep(i, n) {
for (auto a : vx[i]) {
adyp.push_back({ a[0],i,a[2] });
delyp.push_back({ a[1],i,a[2] });
}
}
sort(all(adyp));
sort(all(delyp));
int locad = 0;
int locdel = 0;
stp.clear();
for (int j : ys) {
while (locad < adyp.size() && adyp[locad][0] <= j) {
stp.insert({ adyp[locad][1],adyp[locad][2] });
locad++;
}
while (locdel < delyp.size() && delyp[locdel][0] <= j) {
stp.erase({ delyp[locdel][1],delyp[locdel][2] });
locdel++;
}
rep(i, vy[j].size()) {
int le = vy[j][i][0];
int ri = vy[j][i][1];
int id = vy[j][i][2];
auto itr = prev_itr(stp, { le,-1 });
if (itr != stp.end() && (*itr).first == le - 1) {
addps[le].push_back({ (*itr).second,id });
}
itr = next_itr(stp, { ri,-1 });
if (itr != stp.end() && (*itr).first == ri) {
addps[ri].push_back({ (*itr).second,id });
}
}
}
vector<int> anscs(n);
int cur = 0;
uf u(k);
rep(i, n) {
for (int id : addids[i]) {
cur++;
}
for (auto p : addps[i]) {
if (u.same(p.first, p.second))continue;
cur--;
u.unite(p.first, p.second);
}
anscs[i] = cur;
}
vector<int> anscnt(n + 1);
rep(i, n) {
for (auto a : vx[i]) {
int len = a[1] - a[0];
anscnt[i] += len;
anscnt[i + 1] -= len;
}
}
for(int j:ys){
for (auto a : vy[j]) {
anscnt[a[0]]++;
anscnt[a[1]]--;
}
}
rep(i, n)anscnt[i + 1] += anscnt[i];
ll sum = 0;
rep(i, n) {
sum += anscnt[i];
cout << sum << " " << anscs[i] << "\n";
}
for (int j : ys)vy[j].clear();
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed<<setprecision(10);
//init_f();
//init();
//init2();
//while(true)
//expr();
int t; cin >> t; rep(i, t)
solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 15008kb
input:
3 2 5 2 1 1 1 2 2 3 2 5 2 5 2 1 1 1 3 2 3 2 5 3 3 3 1 1 1 2 3 1 3 2 1 3 2 3
output:
2 1 5 2 3 1 6 1 3 1 4 1 6 2
result:
ok 7 lines
Test #2:
score: 0
Accepted
time: 476ms
memory: 38392kb
input:
2130 2 5 2 1 1 1 2 2 3 2 5 2 5 2 1 1 1 3 2 3 2 5 3 3 3 1 1 1 2 3 1 3 2 1 3 2 3 3 100 51 1 2 2 2 1 4 2 4 1 6 2 6 1 8 2 8 1 10 2 10 1 12 2 12 1 14 2 14 1 16 2 16 1 18 2 18 1 20 2 20 1 22 2 22 1 24 2 24 1 26 2 26 1 28 2 28 1 30 2 30 1 32 2 32 1 34 2 34 1 36 2 36 1 38 2 38 1 40 2 40 1 42 2 42 1 44 2 44 ...
output:
2 1 5 2 3 1 6 1 3 1 4 1 6 2 50 50 100 50 200 1 50 50 150 1 200 1 2 1 4 1 6 1 8 1 10 1 12 1 14 1 16 1 18 1 20 1 22 1 24 1 26 1 28 1 30 1 32 1 34 1 36 1 38 1 40 1 42 1 44 1 46 1 48 1 50 1 52 1 54 1 56 1 58 1 60 1 62 1 64 1 66 1 68 1 70 1 72 1 74 1 76 1 78 1 80 1 82 1 84 1 86 1 88 1 90 1 92 1 94 1 96 1...
result:
ok 355756 lines
Extra Test:
score: 0
Extra Test Passed