记录编号 |
588825 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
雨和卡布奇诺 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.758 s |
提交时间 |
2024-07-01 15:16:08 |
内存使用 |
49.71 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define fi first
#define se second
#define pii pair<int,int>
#define db double
const int N = 2e5+10,M = 1e6+1e5;
const ll mod = 1e9+7;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c <= '9' && c >= '0';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n,m,len,ans;
int t[N],u[N],l[N],k[N],ch[N*5];
vector<int>a[N],b[N],c[N],d[N];
int cnt[N*5],s[N];
priority_queue<pii,vector<pii>,greater<pii> >q[N];
queue<int>q1;
bool v[N];
void update(int x,int z){
cnt[x] += z;
while(!q[x].empty()){
int now = q[x].top().se;
if(cnt[x] >= q[x].top().fi){
if(++s[now] == l[now])q1.push(now);
q[x].pop();
}
else break;
}
}
void solve(){
n = read();
for(int i = 1;i <= n;i++)ch[++len] = t[i] = read(),u[i] = read();
m = read();
for(int i = 1;i <= m;i++){
l[i] = read();
for(int j = 1;j <= l[i];j++)a[i].pb(read()),ch[++len] = a[i][j-1],b[i].pb(read());
k[i] = read();
for(int j = 1;j <= k[i];j++)c[i].pb(read()),ch[++len] = c[i][j-1],d[i].pb(read());
}
sort(ch+1,ch+1+len);
len = unique(ch+1,ch+1+len) - (ch+1);
for(int i = 1;i <= n;i++)t[i] = lower_bound(ch+1,ch+1+len,t[i]) - ch;
for(int i = 1;i <= m;i++){
for(int j = 1;j <= l[i];j++)a[i][j-1] = lower_bound(ch+1,ch+1+len,a[i][j-1]) - ch;
for(int j = 1;j <= k[i];j++)c[i][j-1] = lower_bound(ch+1,ch+1+len,c[i][j-1]) - ch;
}
for(int i = 1;i <= n;i++)cnt[t[i]] = u[i];
//
for(int i = 1;i <= m;i++){
for(int j = 0;j < l[i];j++){
if(cnt[a[i][j]] >= b[i][j])s[i]++;
else q[a[i][j]].push(make_pair(b[i][j],i));
}
if(s[i] == l[i])q1.push(i);
}
while(!q1.empty()){
ans++;
int x = q1.front();q1.pop();
for(int i = 0;i < k[x];i++)update(c[x][i],d[x][i]);
}
printf("%d\n",ans);
}
int main(){
freopen("Cappuccino.in","r",stdin);
freopen("Cappuccino.out","w",stdout);
int t = 1;
while(t--)solve();
return 0;
}