Record of coding:Codeforces 1093E
Posted akonoh
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Record of coding:Codeforces 1093E相关的知识,希望对你有一定的参考价值。
E. Intersection of Permutations
You are given two permutations a and b, both consisting of n elements. Permutation of nn elements is such a integer sequence that each value from 1 to n appears exactly once in it.
You are asked to perform two types of queries with them:
- 1 la ra lb rb — calculate the number of values which appear in both segment [la;ra] of positions in permutation aa and segment [lb;rb] of positions in permutation b;
- 2 x y — swap values on positions x and y in permutation b.
Print the answer for each query of the first type.
It is guaranteed that there will be at least one query of the first type in the input.
/************************************************************************************** * This code is written by akonoh. * * It can only be compiled by c++17 due to the usage of bits/extc++.h * * I used pb_ds to reduce the length of my code * * ************************************************************************************/ #include <bits/stdc++.h> #include <bits/extc++.h> using namespace std; using namespace __gnu_pbds; #define N 200*1000 int n,m; tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> tr[N+7],sb; inline int lb(int x){return x&-x;} void addup(int x,int y) { for(int i = x; i <= n ; i += lb(i)) { tr[i].insert(y); } } void del(int x, int y) { for(int i = x; i <= n; i += lb(i)) { tr[i].erase(y); } } int getans(int x, int y) { int ans = 0; for(int i = x; i > 0; i -= lb(i)) { int p = tr[i].order_of_key(y); if(*tr[i].lower_bound(y)==y)p++; ans += p; //this part is to find how many numbers are smaller or equal to y. } return ans; } int a[N+8],b[N+8]; int main() { scanf("%d%d",&n,&m); for(int i = 1 ; i<= n; i ++) { int x; scanf("%d",&x); a[x]=i; } for(int i = 1; i <= n ;i ++) { int x; scanf("%d",&x); b[i]=a[x];//renumeration } for(int i = 1; i <= n; i ++) addup(i,b[i]); for(int i = 1; i <= m; i ++) { int t; scanf("%d",&t); if(t==1) { int la,ra,lb,rb,ans=0; scanf("%d%d%d%d",&la,&ra,&lb,&rb); ans +=getans(rb,ra); ans -=getans(lb-1,ra); ans -=getans(rb,la-1); ans +=getans(lb-1,la-1); printf("%d ",ans); } else { int x,y; scanf("%d%d",&x,&y); del(x,b[x]); del(y,b[y]); swap(b[x],b[y]); addup(x,b[x]); addup(y,b[y]); } } }
以上是关于Record of coding:Codeforces 1093E的主要内容,如果未能解决你的问题,请参考以下文章
Record these plug-ins of vscode
Laravel eloquent apply whereHas on the latest record of hasMany 关系
csharp: using OleDb Getting the identity of the most recently added record
mysql索引损坏,Record in index `log_time` of table `lts`.`lts_job_log_po` was not found on update
外显子分析报错解决方案bin field of BAM record does not equal value computed based on alignment start and end, a