#include<bits/stdc++.h>
#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define mask(k) (1<<k)
#define mp make_pair
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
char c = getchar_unlocked();
int x = 0;
while (c < '0' || c > '9')
{
c = getchar_unlocked();
}
while (c >= '0' && c <= '9')
{
x = (x << 1) + (x << 3) + c - '0';
c = getchar_unlocked();
}
return x;
}
void phongbeo();
const int inf = 1e18;
const ll mod2 = 1e9+7;
const int mod1 = 998244353;
const ll base=67;
int add(int x,int y)
{
if(x+y>=mod2) x-=mod2;
if(x+y<0)x+=mod2;
return x+y;
}
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a, b, c;
};
struct id
{
int a, b, c, d;
};
struct ie
{
int a, b, c, d, e;
};
int n, m, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int i, s10, s12,k1,k2,k3,s11,lim,w,l,r ;
int kk;
int el = 19;
main()
{
if(fopen(task".inp","r"))
{
fin(task);
fou(task);
}
NHP
/// cin>>s1;
// modwwe
phongbeo();
// checktime
}
vector<int> v,task1[1100007],task2[1100007],ans;
vector<ib> ask1[1100007],ask2[1100007];
vector<ic> mst;
ib a[1100007],dsu[1100007];
id b[1100007];
int val[1100007],query;
multiset<int>s1,s2;
bool cmp2(ib a,ib b)
{
return a.a<b.a;
}
bool cmp(ic a,ic b)
{
return a.c<b.c;
}
void reset()
{
for(int i=1; i<=n; i++)
dsu[i]= {1,i};
}
int get(int x)
{
if(x==dsu[x].b) return x;
return dsu[x].b=get(dsu[x].b);
}
bool noi(int x,int y)
{
x=get(x),y=get(y);
if(x==y) return 0;
if(dsu[x].a<dsu[y].a) swap(x,y);
dsu[x].a+=dsu[y].a;
dsu[y].b=x;
return 1;
}
void phongbeo()
{
cin>>n>>m>>query;
for(int i=1; i<=n; i++)
cin>>a[i].a>>a[i].b,v.pb(a[i].a),v.pb(a[i].b);
for(int i=1; i<=m; i++)
{
cin>>b[i].a>>b[i].b>>b[i].c>>b[i].d;
v.pb(b[i].a);
v.pb(b[i].b);
v.pb(b[i].c);
v.pb(b[i].d);
}
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
for(int i=1; i<=n; i++)
{
a[i].a=lower_bound(v.begin(),v.end(),a[i].a)-v.begin();
a[i].b=lower_bound(v.begin(),v.end(),a[i].b)-v.begin();
ask1[a[i].b].pb({a[i].a,i});
ask2[a[i].a].pb({a[i].b,i});
}
for(int i=1; i<=m; i++)
{
b[i].a=lower_bound(v.begin(),v.end(),b[i].a)-v.begin();
b[i].b=lower_bound(v.begin(),v.end(),b[i].b)-v.begin();
b[i].c=lower_bound(v.begin(),v.end(),b[i].c)-v.begin();
b[i].d=lower_bound(v.begin(),v.end(),b[i].d)-v.begin();
task2[b[i].a].pb(b[i].b);
task2[b[i].c+1].pb(-b[i].b);
task1[b[i].b].pb(b[i].a);
task1[b[i].d+1].pb(-b[i].a);
}
for(int i=0; i<v.size(); i++)
{
for(auto x:task1[i])
{
if(x<0) s1.erase(s1.find(-x));
else s1.insert(x);
}
sort(ask1[i].begin(),ask1[i].end(),cmp2);
int kk=ask1[i].size();
kk--;
for(int j=0; j<kk; j++)
{
auto it=s1.lower_bound(ask1[i][j].a);
if(it!=s1.end()&&*it<=ask1[i][j+1].a) continue;
mst.pb({ask1[i][j].b,ask1[i][j+1].b,v[ask1[i][j+1].a]-v[ask1[i][j].a]});
}
for(auto x:task2[i])
{
if(x<0) s2.erase(s2.find(-x));
else s2.insert(x);
}
sort(ask2[i].begin(),ask2[i].end(),cmp2);
kk=ask2[i].size();
kk--;
for(int j=0; j<kk; j++)
{
auto it=s2.lower_bound(ask2[i][j].a);
if(it!=s2.end()&&*it<=ask2[i][j+1].a) continue;
mst.pb({ask2[i][j].b,ask2[i][j+1].b,v[ask2[i][j+1].a]-v[ask2[i][j].a]});
}
}
sort(mst.begin(),mst.end(),cmp);
reset();
for(auto x:mst)
if(noi(x.a,x.b))
{
val[++dem]=x.c;
val[dem]+=val[dem-1];
ans.pb(x.c);
}
for(int i=1; i<=query; i++)
{
cin>>l>>r;
swap(l,r);
if(ans.size()+l<n)
{
cout<<-1,down
}
else
{
int ss=upper_bound(ans.begin(),ans.end(),r)-ans.begin();
if(ss+l<n)
{
cout<<val[n-l]+l*r,down
}
else
{
cout<<val[ss]+(n-ss)*r,down
}
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
construction.cpp:73:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
73 | main()
| ^~~~
construction.cpp: In function 'int main()':
construction.cpp:11:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | #define fin(x) freopen(x".inp","r",stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
construction.cpp:77:9: note: in expansion of macro 'fin'
77 | fin(task);
| ^~~
construction.cpp:12:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define fou(x) freopen(x".out","w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
construction.cpp:78:9: note: in expansion of macro 'fou'
78 | fou(task);
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |