当前位置: 首页 > news >正文

P4390 [BalkanOI 2007] Mokia 摩基亚

简单二维数组,范围显然接受不了。简单 cdq。

矩阵和,考虑二维前缀和差分,容易将一个 4-side 询问拆成四个 2-side 询问,于是就是三维偏序直接上 cdq。

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define fin(x) freopen(#x".in","r",stdin)
#define fout(x) freopen(#x".out","w",stdout)
#define fr(x) fin(x),fout(x);
#define Fr(x,y) fin(x),fout(y)
#define INPUT(_1,_2,FILE,...) FILE
#define IO(...) INPUT(__VA_ARGS__,Fr,fr)(__VA_ARGS__)
using namespace std;
using namespace __gnu_pbds;
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define cfast ios::sync_with_stdio(false);cin.tie(0),cout.tie(0)
#define ll long long
#define ull unsigned long long
#define intz(x,y) memset((x),(y),sizeof((x)))
char *p1,*p2,buf[100000];
#define nc() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
#define tup(x) array<int,(x)>
inline ll read(){ll x=0,f=1;char ch=nc();while(ch<48||ch>57){if(ch=='-')f=-1;ch=nc();}while(ch>=48&&ch<=57)x=x*10+ch-48,ch=nc();return x*f;
}
//void write(int x){cout<<x<<' ';}
//void write(pii x){cout<<"P("<<x.fi<<','<<x.se<<")\n";}
//void write(vector<auto>x){for(auto i:x)write(i);cout<<'\n';}
//void write(auto *a,int l,int r){for(int i=l;i<=r;i++)write(a[i]);cout<<'\n';}
inline ll lowbit(ll x){return x&-x;}
#define pcount(x) __builtin_popcount(x)
inline void cmx(ll &x,ll y){if(y>x)x=y;}
inline void cmn(ll &x,ll y){if(y<x)x=y;}
const int mod=998244353;
#define b(x) (x).begin()
ll qp(ll x,int y){ll res=1;for(;y;x=x*x%mod,y>>=1)if(y&1)res=res*x%mod;return res;}
const int N=2e5+5,M=2e6+5;
struct node{int op,x,y,v,f;};
int n,t[M],tot,ans[N];vector<node>q;
void upd(int x,int d){for(;x<=n;x+=lowbit(x))t[x]+=d;}
int ask(int x){int res=0;for(;x;x-=lowbit(x))res+=t[x];return res;}
bool cmp(node x,node y){return x.x<y.x;}
void cdq(int L,int R){if(L==R)return;int mid=L+R>>1;cdq(L,mid),cdq(mid+1,R);sort(b(q)+L,b(q)+1+mid,cmp),sort(b(q)+1+mid,b(q)+1+R,cmp);vector<pii>w;for(int l=L,r=mid+1;r<=R;r++){while(l<=mid&&q[l].x<=q[r].x)(q[l].op==1?upd(q[l].y,q[l].v),w.pb(mp(q[l].y,q[l].v)),1:0),++l;if(q[r].op==2)ans[q[r].v]+=ask(q[r].y)*q[r].f;}for(pii i:w)upd(i.fi,-i.se);
}
inline void UesugiErii(){cin>>n,cin>>n;q.pb(node{});int op,x,y,x_,y_,z;while(cin>>op){if(op==3)break;cin>>x>>y;if(op==1)cin>>z,q.pb(node{1,x,y,z});else ++tot,cin>>x_>>y_,q.pb(node{2,x-1,y-1,tot,1}),q.pb(node{2,x-1,y_,tot,-1}),q.pb(node{2,x_,y-1,tot,-1}),q.pb(node{2,x_,y_,tot,1});}
//	for(node i:q)cout<<i.op<<' '<<i.x<<' '<<i.y<<' '<<i.v<<'\n';cdq(1,q.size()-1);for(int i=1;i<=tot;i++)cout<<ans[i]<<'\n'; 
}
signed main(){//IO();//cfast;int _=1;//cin>>_;for(;_;_--)UesugiErii();return 0;
}
http://www.rkmt.cn/news/69089.html

相关文章:

  • 日总结 34
  • Avro
  • 关于C:scanf()的一些注意事项
  • 2025年产品动画制作公司最新推荐,聚焦资质、案例、售后的实力品牌深度解析!
  • 把一个软件窗口部分内容置顶 的软件下载
  • 哔哩哔哩野生API宝典:从入门到精通
  • 第2篇Scrum冲刺博客
  • PbootCMS 指定栏目标签详解与应用场景
  • 动态数组
  • 【Linux进阶系列】:线程(上) - 详解
  • Solon AI 开发学习8 - chat - Vision(理解)图片、声音、视频
  • Python全栈项目:基于Django的电子商务平台编写
  • 【触想智能】工业触控一体机在工业应用中扮演的角色以及其应用场景分析
  • 租房买房必看4门口乱堆杂物,正在悄悄“截断”全家人的好运气!
  • 大模型安全:共享 GPU 本地内存泄露
  • 2025年12月AI SEO优化公司推荐:解锁智能搜索流量新密码
  • 2025年12月ChatGPT优化排名公司推荐
  • 2025年AI教育培训课程推荐榜:覆盖AI培训全场景指南
  • 2025年12月西安装修家装公司TOP5推荐:老房翻新/室内设计优选企业
  • 模切机厂家有哪些?国内知名企业推荐
  • Webpack/Vite等构建工具打包后,线上代码报错但本地正常,怎么办?
  • 哪些品牌的妇科炎症外用药效果好
  • 2025年热镀锌带钢口碑厂家TOP10,实力见证,镀锌打包扣/镀锌打包钢带/烤漆打包带/冷镀锌打包带/打包铁条热镀锌带钢生产厂家
  • 漆面保护膜品牌公司排名:国内优质车膜品牌推荐
  • 推荐专业的北京离婚财产纠纷律师及服务解析
  • 推荐靠谱的车衣品牌:市场热门选择及特点解析
  • 争取孩子抚养权找哪个律师靠谱?专业选择参考
  • 北京口碑好的涉外离婚律师选择指南与实务解析
  • 哪些AI企业有投资价值?聚焦行业潜力标的
  • 第十周第三天10.3