제출 #1309478

#제출 시각아이디문제언어결과실행 시간메모리
1309478thuhienneRailway Trip 2 (JOI22_ho_t4)C++20
16 / 100
2095 ms2860 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define thuhien ""
#define re exit(0);

const int maxm = 2e5 + 9;
const int maxn = 1e5 + 9;

int n,k,m;
pair <int,int> line[maxm];
int q;

int maxreach[maxn],minreach[maxn];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
	if (fopen(thuhien".inp","r")) {
	   freopen(thuhien".inp","r",stdin);
	   freopen(thuhien".out","w",stdout);
	}
	
	cin >> n >> k >> m;
	
	for (int i = 1;i <= n;i++) maxreach[i] = minreach[i] = i;
	
	for (int i = 1;i <= m;i++) {
		cin >> line[i].first >> line[i].second;
		
		if (line[i].first < line[i].second) {
			for (int j = line[i].first;j <= min(line[i].first + k - 1,line[i].second - 1);j++) {
				maxreach[j] = max(maxreach[j],line[i].second);
			}
		} else {
			for (int j = line[i].first;j >= max(line[i].first - k + 1,line[i].second + 1);j--) {
				minreach[j] = min(minreach[j],line[i].second);
			}
		}
		
	}
	
	int q;cin >> q;
	while (q--) {
		int s,t;cin >> s >> t;
		
		int l = s,r = s,nextl,nextr,res = 0;
		while (r < t || l > t) {
			res++;
			
			nextl = l,nextr = r;
			for (int i = l;i <= r;i++) {
				nextl = min(nextl,minreach[i]);
				nextr = max(nextr,maxreach[i]);
			}
			
			if (l == nextl && r == nextr) {
				res = 1e9;
				break;
			}
			l = nextl,r = nextr;
		}
		
		cout << (res == 1e9 ? -1 : res) << '\n';
		
	}
	
	

}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:22:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |            freopen(thuhien".inp","r",stdin);
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |            freopen(thuhien".out","w",stdout);
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...