답안 #1041413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041413 2024-08-02T03:23:54 Z hungeazy 전차 (CEOI13_tram) C++17
65 / 100
130 ms 4856 KB
/*
* @Author: hungeazy
* @Date:   2024-08-02 09:20:31
* @Last Modified by:   hungeazy
* @Last Modified time: 2024-08-02 10:23:40
*/
#include <bits/stdc++.h>
// #pragma GCC optimize("O3")  
// #pragma GCC optimize("unroll-loops")  
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")  
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define ull unsigned long long
#define sz(x) x.size()
#define sqr(x) (1LL * (x) * (x))
#define all(x) x.begin(), x.end()
#define fill(f,x) memset(f,x,sizeof(f))
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define FOD(i,r,l) for(int i=r;i>=l;i--)
#define ii pair<int,int>
#define iii pair<int,ii>
#define di pair<ii,ii>
#define vi vector<int>
#define vii vector<ii>
#define mii map<int,int>
#define fi first
#define se second
#define pb push_back
#define MOD 1000000007
#define __lcm(a,b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define MASK(i) (1LL << (i))
#define c_bit(i) __builtin_popcountll(i)
#define BIT(x,i) ((x) & MASK(i))
#define SET_ON(x,i) ((x) | MASK(i))
#define SET_OFF(x,i) ((x) & ~MASK(i))
#define oo 1e18
#define name ""
#define endl '\n'
#define time() cerr << endl << "-------------Time:" << 1000.0 * clock() / CLOCKS_PER_SEC << "ms.";
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
const int N = (int)1e6+10;
int n,q;

namespace sub12 {

	int sz = 0,d[N][2];
	ii save[N];
	bool check[N][2];

	int DIST(ii a, ii b)
	{
		return sqr(a.fi-b.fi)+sqr(a.se-b.se);
	}

	ii calc()
	{
		if (!sz) return {1,0};
		FOR(i,1,n)
			FOR(j,0,1) d[i][j] = oo;
		ii pos = {0,0};
		FOR(i,1,n)
		{
			FOR(j,0,1)
				if (!check[i][j])
				{
					if (pos.fi) d[i][j] = min(d[i][j],DIST({i,j},{pos.fi,0}));
					if (pos.se) d[i][j] = min(d[i][j],DIST({i,j},{pos.se,1}));
					if (check[i][j^1]) d[i][j] = 1;
				}
			if (check[i][0]) pos.fi = i;
			if (check[i][1]) pos.se = i; 
		}
		pos = {0,0};
		int ans = -oo;
		FOD(i,n,1)
		{
			FOR(j,0,1)
				if (!check[i][j])
				{
					if (pos.fi) d[i][j] = min(d[i][j],DIST({i,j},{pos.fi,0}));
					if (pos.se) d[i][j] = min(d[i][j],DIST({i,j},{pos.se,1}));
					maximize(ans,d[i][j]);
				}
			if (check[i][0]) pos.fi = i;
			if (check[i][1]) pos.se = i; 
		}
		FOR(i,1,n)
			FOR(j,0,1)
				if (!check[i][j] and ans == d[i][j]) return {i,j};
	}

	void solve(void)
	{
		int pos = 0;
		while (q--)
		{
			char type;
			cin >> type;
			if (type == 'E')
			{
				++pos;
				save[pos] = calc();
				check[save[pos].fi][save[pos].se] = true;
				cout << save[pos].fi << " " << save[pos].se+1 << endl;
				++sz;
			}
			else 
			{
				int x;
				cin >> x;
				++pos;
				check[save[x].fi][save[x].se] = false;
				--sz;
			}
		}
	}	
	
}

namespace sub3 {

	int sz = 0;
	ii save[N];
	bool check[N][3];
	multiset<int> st;

	void solve(void)
	{
		FOR(i,1,q)
		{
			char type;
			cin >> type;
			if (type == 'E')
			{
				sz++;
				if (sz == 1) 
				{
					cout << "1 1" << endl;
					st.insert(1);
					check[1][1] = 1;
					save[i] = {1,1};
					continue;
				}	
				vi v(all(st)),vec;
				// for (auto it = st.begin(); it != st.end(); it++) v.pb(*it);
				vec.pb(1); vec.pb(n);
				if (v.size() >= 2)
				{
					FOR(i,0,v.size()-2)
					{
						int x = (v[i]+v[i+1])/2, y = (v[i]+v[i+1]+1)/2;
						vec.pb(x); vec.pb(y);
					}
				}
				sort(all(vec)); vec.erase(unique(all(vec)),vec.end());
				ii vt;
				int ans = -oo;
				FOR(i,0,vec.size()-1)
					FOR(j,1,2)
					{
						auto it = st.lower_bound(vec[i]);
						int mi = oo;
						if (it != st.end())
						{
							int x = *it;
							FOR(k,1,2)
								if (check[x][k])
								{
									int cost = min(sqr(vec[i]-x),(int)oo)+(j != k);
									mi = min(mi,cost);
								} 
						}
						if (it != st.begin())
						{
							int x = *(--it);
							FOR(k,1,2)
								if (check[x][k])
								{
									int cost = min(sqr(vec[i]-x),(int)oo)+(j != k);
									mi = min(mi,cost);
								}
						}
						if (ans < mi) ans = mi, vt = {vec[i],j};
					}
				cout << vt.fi << " " << vt.se << endl;
				save[i] = vt;
				st.insert(vt.fi);
				check[vt.fi][vt.se] = true;
			}
			else 
			{
				int x;
				cin >> x;
				ii vt = save[x];
				st.erase(st.find(vt.fi));
				check[vt.fi][vt.se] = false;
				--sz;
			}
		}
	}

}

signed main()
{
    fast;
    if (fopen(name".inp","r"))
    {
    	freopen(name".inp","r",stdin);
    	freopen(name".out","w",stdout);
    }
    cin >> n >> q;
    // if (n <= 2e3 and q <= 2e3) sub12::solve();
    if (n <= 2e5 and q <= 2e3) sub3::solve();
    time();
    return 0;
}

Compilation message

tram.cpp: In function 'void sub3::solve()':
tram.cpp:19:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 | #define FOR(i,l,r) for(int i=l;i<=r;i++)
......
  153 |      FOR(i,0,v.size()-2)
      |          ~~~~~~~~~~~~~~          
tram.cpp:153:6: note: in expansion of macro 'FOR'
  153 |      FOR(i,0,v.size()-2)
      |      ^~~
tram.cpp:19:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 | #define FOR(i,l,r) for(int i=l;i<=r;i++)
......
  162 |     FOR(i,0,vec.size()-1)
      |         ~~~~~~~~~~~~~~~~         
tram.cpp:162:5: note: in expansion of macro 'FOR'
  162 |     FOR(i,0,vec.size()-1)
      |     ^~~
tram.cpp: In function 'std::pair<long long int, long long int> sub12::calc()':
tram.cpp:94:2: warning: control reaches end of non-void function [-Wreturn-type]
   94 |  }
      |  ^
tram.cpp: In function 'int main()':
tram.cpp:213:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  213 |      freopen(name".inp","r",stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
tram.cpp:214:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  214 |      freopen(name".out","w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 2636 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
3 Correct 13 ms 2588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 2640 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
3 Correct 13 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 4856 KB Output is correct
2 Correct 5 ms 2592 KB Output is correct
3 Correct 15 ms 4836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 4696 KB Output is correct
2 Correct 6 ms 2592 KB Output is correct
3 Correct 14 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -