Submission #1032660

# Submission time Handle Problem Language Result Execution time Memory
1032660 2024-07-24T05:43:16 Z KasymK Strange Device (APIO19_strange_device) C++17
Compilation error
0 ms 0 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int MOD = 1e9+7;
const int N = 1e5+5;
const ll INF = 1e18;
int v[N];

int main(){
	// freopen("file.txt", "r", stdin);
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	if (true) {
		// (2x % a, 0)
		// 2x % a == 0
		// if a is odd, then the ans is of length a (the 2 will never
		// contribute)
		// if a is even, then the ans of of length a/2
		ll ans = (a%2 == 0 ? a/2 : a);
		if (b){
		  // w (B + 1) mod A = 0
		  if (b/gcd(a, b+1) >= (INF+1)/a)
		    ans = INF+1;
		  else
		  	ans = a/gcd(a, b+1)*b;
		}
		vector<pair<ll, ll>> v;
		map<ll, ll> mp;
		while(n--){
		  ll l, r;
		  scanf("%lld%lld", &l ,&r);
		  ll _l = l%ans, _r = r%ans;
		  if (r-l+1 >= ans){
		  	printf("%lld\n", ans);
		    return 0;
		  }
		  if(_l > _r)
		    v.pb({_l, ans - 1}), v.pb({0, _r});
		  else
		    v.pb({_l, _r});
		}
		for(auto &[l, r] : v)
		  mp[l] = max(mp[l], r);
		ll r_ = 0;
		ans = 0;
		for(auto &i : mp){
		  if(i.ss < r_)
		    continue;
		  r_ = max(r_, i.ff);
		  ans += i.ss-r_+1;
		  r_ = i.ss+1;
		}
		printf("%lld\n", ans);
		return 0;
	}
	set<pair<ll, ll>> st;
	while(n--){
		ll l, r;
		scanf("%lld%lld", &l, &r);
		for(ll x = l; x <= r; ++x)
		  st.insert({(x+x/b)%a, x%b});
	}
    ll answer = st.size();
    printf("%lld\n", answer);
	return 0;
}#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int MOD = 1e9+7;
const int N = 1e5+5;
const ll INF = 1e18;
int v[N];

int main(){
	// freopen("file.txt", "r", stdin);
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	if (true) {
		// (2x % a, 0)
		// 2x % a == 0
		// if a is odd, then the ans is of length a (the 2 will never
		// contribute)
		// if a is even, then the ans of of length a/2
		ll ans = (a%2 == 0 ? a/2 : a);
		if (b){
		  // w (B + 1) mod A = 0
		  if (b/gcd(a, b+1) >= (INF+1)/a)
		    ans = INF+1;
		  else
		  	ans = a/gcd(a, b+1)*b;
		}
		vector<pair<ll, ll>> v;
		map<ll, ll> mp;
		while(n--){
		  ll l, r;
		  scanf("%lld%lld", &l ,&r);
		  ll _l = l%ans, _r = r%ans;
		  if (r-l+1 >= ans){
		  	printf("%lld\n", ans);
		    return 0;
		  }
		  if(_l > _r)
		    v.pb({_l, ans - 1}), v.pb({0, _r});
		  else
		    v.pb({_l, _r});
		}
		for(auto &[l, r] : v)
		  mp[l] = max(mp[l], r);
		ll r_ = 0;
		ans = 0;
		for(auto &i : mp){
		  if(i.ss < r_)
		    continue;
		  r_ = max(r_, i.ff);
		  ans += i.ss-r_+1;
		  r_ = i.ss+1;
		}
		printf("%lld\n", ans);
		return 0;
	}
	set<pair<ll, ll>> st;
	while(n--){
		ll l, r;
		scanf("%lld%lld", &l, &r);
		for(ll x = l; x <= r; ++x)
		  st.insert({(x+x/b)%a, x%b});
	}
    ll answer = st.size();
    printf("%lld\n", answer);
	return 0;
}

Compilation message

strange_device.cpp:73:2: error: stray '#' in program
   73 | }#include "bits/stdc++.h"
      |  ^
strange_device.cpp:73:3: error: 'include' does not name a type
   73 | }#include "bits/stdc++.h"
      |   ^~~~~~~
strange_device.cpp:81:23: error: redefinition of 'template<class T> bool umin(T&, T)'
   81 | template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
      |                       ^~~~
strange_device.cpp:9:23: note: 'template<class T> bool umin(T&, T)' previously declared here
    9 | template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
      |                       ^~~~
strange_device.cpp:82:23: error: redefinition of 'template<class T> bool umax(T&, T)'
   82 | template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
      |                       ^~~~
strange_device.cpp:10:23: note: 'template<class T> bool umax(T&, T)' previously declared here
   10 | template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
      |                       ^~~~
strange_device.cpp:83:11: error: redefinition of 'const int MOD'
   83 | const int MOD = 1e9+7;
      |           ^~~
strange_device.cpp:11:11: note: 'const int MOD' previously defined here
   11 | const int MOD = 1e9+7;
      |           ^~~
strange_device.cpp:84:11: error: redefinition of 'const int N'
   84 | const int N = 1e5+5;
      |           ^
strange_device.cpp:12:11: note: 'const int N' previously defined here
   12 | const int N = 1e5+5;
      |           ^
strange_device.cpp:85:10: error: redefinition of 'const long long int INF'
   85 | const ll INF = 1e18;
      |          ^~~
strange_device.cpp:13:10: note: 'const long long int INF' previously defined here
   13 | const ll INF = 1e18;
      |          ^~~
strange_device.cpp:86:5: error: redefinition of 'int v [100005]'
   86 | int v[N];
      |     ^
strange_device.cpp:14:5: note: 'int v [100005]' previously declared here
   14 | int v[N];
      |     ^
strange_device.cpp:88:5: error: redefinition of 'int main()'
   88 | int main(){
      |     ^~~~
strange_device.cpp:16:5: note: 'int main()' previously defined here
   16 | int main(){
      |     ^~~~
strange_device.cpp: In function 'int main()':
strange_device.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d%d%d", &n, &a, &b);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%lld%lld", &l ,&r);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~
strange_device.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   scanf("%lld%lld", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
strange_device.cpp: In function 'int main()':
strange_device.cpp:91:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |  scanf("%d%d%d", &n, &a, &b);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:110:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |     scanf("%lld%lld", &l ,&r);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~
strange_device.cpp:138:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  138 |   scanf("%lld%lld", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~