結果
| 問題 | No.875 Range Mindex Query |
| コンテスト | |
| ユーザー |
horiesiniti
|
| 提出日時 | 2023-01-20 21:39:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,569 bytes |
| 記録 | |
| コンパイル時間 | 871 ms |
| コンパイル使用メモリ | 84,144 KB |
| 実行使用メモリ | 99,396 KB |
| 最終ジャッジ日時 | 2024-06-23 09:33:14 |
| 合計ジャッジ時間 | 16,933 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 14 TLE * 4 |
ソースコード
//範囲内の最小値を求めよという問題と間違えた。
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <vector>
int maxr=131071;
//int maxr=7;
using namespace std;
map<int,int> st[270000];
map<int,int> ms;
int f3(int no,int l,int r,int l2,int r2){
int res=(*(st[no].begin())).first;
if(r2<l || r<l2){
return maxr*2;
}else if(l2==r2){
return res;
}else if(l<=l2 && r2<=r){
//cout<<l<<" "<<l2<<" "<<r2<<" "<<r<<" "<<res<<endl;
return res;
}else{
int m=(r2+l2)/2;
res=f3(no*2+1,l,r,l2,m);
res=min(res,f3(no*2+2,l,r,m+1,r2));
}
return res;
}
void f2(int no,int p1,int n1,int n2,int l,int r){
if(no!=0){
st[no][n1]--;
st[no][n2]++;
if(st[no][n1]==0)st[no].erase(n1);
}
if(l==r){
return ;
}else{
int m=(l+r)/2;
if(p1<=m){
f2(no*2+1,p1,n1,n2,l,m);
}else{
f2(no*2+2,p1,n1,n2,m+1,r);
}
}
}
void f(int no,int p1,int n1,int l,int r){
if(no==0){
st[no][1]=1;
}else{
st[no][n1]++;
}
if(l==r){
return ;
}else{
int m=(l+r)/2;
if(p1<=m){
f(no*2+1,p1,n1,l,m);
}else{
f(no*2+2,p1,n1,m+1,r);
}
}
}
int main() {
int n,q;
cin>>n>>q;
vector<int> as;
for(int i=0;i<n;i++){
int a;
cin>>a;
as.push_back(a);
f(0,i,a,0,maxr);
ms[a]=i;
}
for(int i=0;i<q;i++){
int e,l,r;
cin>>e>>l>>r;
l--;
r--;
if(e==1){
f2(0,l,as[l],as[r],0,maxr);
f2(0,r,as[r],as[l],0,maxr);
ms[as[l]]=r;
ms[as[r]]=l;
swap(as[l],as[r]);
}else{
//cout<<f3(0,l,r,0,maxr)<<endl;
cout<<ms[f3(0,l,r,0,maxr)]+1<<endl;
}
}
return 0;
}
horiesiniti