首页 > 编程语言 >2023年中国传媒大学程序设计大赛 G.跳台滑雪 线段树

2023年中国传媒大学程序设计大赛 G.跳台滑雪 线段树

时间:2023-03-22 17:35:05浏览次数:60  
标签:std int 跳台 long 传媒大学 score 2023 include define

传送门

#include <iostream>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <numeric>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <unordered_set>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <tuple>
 
#define int long long 
#define all(a) a.begin(), a.end()
#define cnt0(x) __builtin_ctz(x)
#define endl '\n'
#define itn int
#define ll long long
#define ull unsigned long long
#define rep(i, a, b) for(int i = a;i <= b; i ++)
#define per(i, a, b) for(int i = a;i >= b; i --)
#define cntone(x) __builtin_popcount(x)
#define db double
// #define fs first
// #define se second
#define AC main(void)
#define HYS std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
typedef std::pair<int, int > PII;
typedef std::pair<int, std::pair<int, int>> PIII;
typedef std::pair<ll, ll> Pll;
typedef std::pair<double, double> PDD;
typedef std::pair<double, int> PDI;
using ld = double long;
const long double eps = 1e-9;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;


int n , m, _;
int ans = INF;

int d1[] = {0, 0, 1, -1};
int d2[] = {1, -1, 0, 0};

struct node{
	int l, r;
	double x;
	int id, score;
}tr[N << 2];

struct node1{
	int fs;
	double se;
	int id;
	
	friend bool operator < (const node1 x, const node1 y){
		if(x.fs != y.fs)	return x.fs < y.fs;
		if(x.se != y.se)	return x.se < y.se;
		return x.id < y.id;
	};
}a[N];

int score[N];

inline void pushup(int u){
	if(tr[u << 1].x < tr[u << 1 | 1].x){
		tr[u].x = tr[u << 1 | 1].x;
		tr[u].id = tr[u << 1 | 1].id;
		tr[u].score = tr[u << 1 | 1].score;
	}
	else if(tr[u << 1].x > tr[u << 1 | 1].x){
		tr[u].x = tr[u << 1].x;
		tr[u].id = tr[u << 1].id;
		tr[u].score = tr[u << 1].score;
	}	
	else{
		if(tr[u << 1].score > tr[u << 1 | 1].score){
			tr[u].x = tr[u << 1].x;
			tr[u].id = tr[u << 1].id;
			tr[u].score = tr[u << 1].score;
		}	
		else if(tr[u << 1].score < tr[u << 1 | 1].score){
			tr[u].x = tr[u << 1 | 1].x;
			tr[u].id = tr[u << 1 | 1].id;
			tr[u].score = tr[u << 1 | 1].score;
		}	
		else{
			if(tr[u << 1].id < tr[u << 1 | 1].id){
				tr[u].x = tr[u << 1].x;
				tr[u].id = tr[u << 1].id;
				tr[u].score = tr[u << 1].score;
			}	
			else{
				tr[u].x = tr[u << 1 | 1].x;
				tr[u].id = tr[u << 1 | 1].id;
				tr[u].score = tr[u << 1 | 1].score;
			}
		}
	}
}

inline void build_tree(int u, int l, int r){
	tr[u] = {l, r};
	if(l == r){
		tr[u].x = a[l].se;
		tr[u].id = a[l].id;
		tr[u].score = a[l].fs;
		return ;
	}
	
	int mid = l + r >> 1;
	build_tree(u << 1, l, mid);
	build_tree(u << 1 | 1, mid + 1, r);
	
	pushup(u);
}

inline void pushup(node &a, node b){
	if(a.x > b.x)	return ;
	if(a.x < b.x)	a = b;
	else{
		if(a.score > b.score)	return ;
		if(a.score < b.score)	a = b;
		else{
			if(a.id < b.id)	return ;
			a = b;
		}
	}
}

inline node query(int u, int l, int r){
	if(tr[u].l >= l && tr[u].r <= r)	return tr[u];
	
	int mid = tr[u].l + tr[u].r >> 1;
	node ans;
	ans.id = INF;
	ans.x = 0.0;
	ans.score = 0ll;
	if(l <= mid){
		node tmp = query(u << 1, l, r);
		pushup(ans, tmp);
	}	
	if(r > mid){
		node tmp = query(u << 1 | 1, l, r);
		pushup(ans, tmp);
	}	
	
	return ans;
}

int g[N];

inline void solve(){
	int k;
	std::cin >> n >> m >> k;
	double mx = 0;
	int pos = INF;
	int sc = 0;
	int mxs = 0;
	for(int i = 1; i <= n; i ++){
		std::cin >> a[i].se >> a[i].fs;
		a[i].id = i - 1;
		if(a[i].se > mx){
			mx = a[i].se;
			pos = i - 1;
			sc = a[i].fs;
		}else if(a[i].se == mx){
			if(a[i].fs > sc){
				mx = a[i].se;
				pos = i - 1;
				sc = a[i].fs;
			}else if(a[i].fs == sc){
				if(pos < a[i].id)	continue;
				sc = a[i].fs;
				mx = a[i].se;
				pos = i - 1;
			}
		}	
		
		mxs = std::max(mxs, a[i].fs);
	}
	
	std::sort(a + 1, a + n + 1);
	
	for(int i = 1; i <= n; i ++)	g[i] = a[i].fs;
	
	build_tree(1, 1, n);
	
	for(int i = 1; i <= m; i ++)	std::cin >> score[i];
	
	std::sort(score + 1, score + m + 1, std::greater<int>());
	
	while(k --){
		int rk, s;
		std::cin >> s >> rk;
		if(rk > m || score[rk] <= s){
			std::cout << pos << '\n';
			continue;
		}	
		
		int c = score[rk] - s;
		
		
		if(c > mxs){
			std::cout << -1 << '\n';
			continue;
		}
		int position = std::lower_bound(g + 1, g + n + 1, c) - g;
		node ans = query(1, position, n);
		std::cout << ans.id << '\n';
	}
}

signed AC{
   	HYS
   	
	_ = 1;
   	//std::cin >> _;
	while(_ --)
    	solve();

    return 0;
}

标签:std,int,跳台,long,传媒大学,score,2023,include,define
From: https://www.cnblogs.com/qdhys/p/17244817.html

相关文章

  • 2023年MathorCup数学建模A题B题C题D题思路汇总 妈妈杯建模思路
    0赛题思路(赛题出来以后第一时间分享)企鹅qun7144526211竞赛信息MathorCup高校数学建模挑战赛(以下简称“竞赛”)是由中国优选法统筹法与经济数学研究会主办的面向全......
  • (2023版)一套教程搞定k8s安装到实战 | Kubernetes学习路线
    视频来源:B站《(2022版)最新、最全、最详细的Kubernetes(K8s)教程,从K8s安装到实战一套搞定》一边学习一边整理老师的课程内容及试验笔记,并与大家分享,侵权即删,谢谢支持! ......
  • C/C++手机通信录[2023-03-22]
    C/C++手机通信录[2023-03-22]程序设计题目5:手机通信录【问题描述】用C/C++设计出模拟手机通信系统,能实现对手机中的通信录进行添加、修改、查询等功能。【基本要求】......
  • SMU Spring 2023 Trial Contest Round 1(6/8)
    SMUSpring2023TrialContestRound1(6/8)A.PrependandAppendPrependandAppend只需考虑给定字符串两端是否符合10或01即可,双指针从两端模拟即可。#include<iost......
  • 2023/03/18(六)雨,下一天;应该睡一天
    下雨天还有些冷,继续收拾屋子;休息日也就没喝咖啡,昏昏沉沉的;北京说是天儿很好。把小宝的写字台和我的对调了一下,这样他和姐姐的桌子面积一样了,再慢慢收拾其他的东西。前几......
  • AutoCloseLockNote 2023年3月22日
    AutoCloseLockNote2023年3月22日 REM我的腾讯QQ电子邮箱地址是[email protected]说明:我把SynologyDiskStationDS3622xs+群晖NAS网络附属存储服务器的管理......
  • 2023.3.21晚报
    1.英语元音发音2.算法:红蓝白三色球排序(题目就不写了,leetcode上有)解法思路:对0,1生成两个指针,遍历数组,当数组数目不为指针所指向数字时向后遍历,与指向数字相等时则与当前指......
  • 每日总结2023/3/21
    今天进行了Android的地铁查询操作,主要是进行了简单的前两步,线路和站点查询,并为Android安装了搜狗输入法,以保障汉字的输入。代码行大概50 优化更改textview使之高度变......
  • day21 (2023.3.21)
    1.迭代List接口类型容器 运行结果: 2.迭代Set接口类型容器 运行结果: 3.迭代Map接口类型容器 运行结果: 4.在迭代器中删除元素: 运行结果: 5.操......
  • 2023/3/21
    今天最大的进度,就是配置好安卓的PDF的开源库。之前找了很长时间的开源库,但是往往就是配置依赖的时候死掉。不仅仅需要在build.gradle里面导入依赖。而且还需要在setting.gr......