---
# System prepended metadata

title: 測資
tags: [Code]

---

---
tags: Code
---

# 測資


## .in
```cpp=
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
#define V vector
#define pii pair<int,int>
#define f first
#define s second
#define TP template<typename T> 
#define EB emplace_back
#define time_s CLOCKS_PER_SEC
#define endl '\n'
using namespace std;

fstream fin, fout;

V<int> nums = {500, 1000, 5000, 10000}; //number of test data
V<pii> ranges = {{1000, 1e6}, {1000, 1e6}, {2000, 1e9}, {1e6, 1e9}}; // the range of the test
  
const string id = "a683";

//random
mt19937 gen(time(NULL));

clock_t t_start, t_end;



string trans(int x) {
	return string{char('0' + (x / 10)) , char('0' + (x % 10))};
}



TP
void mtc(int number,pii range, V<T> & vc) { // make test cases 
	// make the test cases
	uniform_int_distribution<int> dis(range.f, range.s);
	
	for(int i = 0; i < number; i++) {
		int a, b;
		do{a = dis(gen), b = dis(gen);} while(a == b);
		
		vc.EB(a, b);
		
		fin << a << ' ' << b;
		if(i + 1 != number) fin << endl;
	}
	
}

int main () {

	for(int i = 0;i < 20; i++){ //the i-th test case
		cout << "---------------------------------" << endl;
		fin.open(id  + "_"+ trans(i) + ".in", ios::out);

		int number = nums[i/5];	
		pii range = ranges[i/5];
		int N = nums[i/5];
		
			
		fin << N << ' ' << number << endl;

		cout << "Making test " << i << " cases" << endl;
		t_start = clock();
		
		V<pii> vc;
		mtc(number, range, vc);
		t_end = clock();
		cout << "Complete, Use (" << (double)(t_end - t_start) / time_s << ") second" << endl;	
		
		 
		fin.close();

	}
}
```


## .out
```cpp =
#include <bits/stdc++.h>
using namespace std;

#define V vector
const string id = "a683";
const int mod = 1e9 + 7;
fstream fin, fout;
clock_t t_start, t_end;
string trans(int x) {
	return string{char('0' + (x / 10)), char('0' + (x % 10))};
}
int main () {
	
	for(int t_i = 0; t_i < 20; t_i++) {
		t_start = clock();
		fin.open(id + "_" + trans(t_i) + ".in", ios::in);
		fout.open(id + "_" + trans(t_i) + ".out", ios::out);
		
		//solution
        /*
            把cin, cout 換成 fin, fout
            int N;
            fin >> N;
            fout << N;
        
         */
		fin.close();
		fout.close();
		t_end = clock();
		cout << "Build" << t_i << "-th test cases use" << (double)(t_end - t_start)/CLOCKS_PER_SEC << endl;;
	} 
			
} 
```


## 測資 version-2

```cpp=

#include<bits/stdc++.h>
#include<cxxabi.h>
using namespace std;

#define CPS CLOCKS_PER_SEC

mt19937 gen( time(0));
#define Data_type int
const string problem_id = "a842";

const int test_amount = 20;

const map< pair<int,int>, map< string, pair<Data_type,Data_type> > > test_case_range= {
    {
        make_pair(0, 3),
        {
            { "N", make_pair( (Data_type) 1e4, (Data_type)1e4 )},
            { "Q", make_pair( (Data_type) 1e4-3, (Data_type)1e4-3 )}
            //{ "b", make_pair( (T)1, (T)100000000 )}
        }
    },
    {
        make_pair(4, 9),
        {
            { "N", make_pair( (Data_type) 1e5, (Data_type)1e5 )},
            { "Q", make_pair( (Data_type) 20, (Data_type)20)}
            //{ "b", make_pair( (Data_type) 1, (Data_type) 100000000 )}
        }
    },//...........
    {
        make_pair(10, 19),
        {
            { "N", make_pair( (Data_type) 5e5, (Data_type)5e5 )},
            { "Q", make_pair( (Data_type) 5e5-3, (Data_type)5e5-3 )}
            //{ "b", make_pair( (Data_type) 1, (Data_type) 100000000 )}
        }
    }//...........
};






//--------------------------------------------------------------//
struct test_data {
    decltype((test_case_range.begin())->second) get_data(int nth) {
        for( auto &i : test_case_range ) {
            if( i.first.first <= nth && nth <= i.first.second ) return i.second;
        }
    }
};

/*--------------TIME COUNT-----------------------------*/

class Time {
public:
    double get_between( ) {
        t_end = clock();
        double ans = get_time(t_tmp, t_end);
        t_tmp = t_end;
        return ans;
    }
    double get_all_time() { t_end = clock(); return get_time( t_start, t_end);}
    double get_time(double t1, double t2) {return double(t2-t1)/double(CPS);};
    void start(){t_start = t_tmp =clock();}
    TIME(){};
private:
    clock_t t_start, t_end, t_tmp;
};


/*---------------DEBUG TOOL--------------------------*/

class debug_tool {
public:
    template<typename T>
    string get_type(T val,bool short_name = true);
    string ReplaceAll( string str, const string& from, const string& to);
    template<typename T>
    void _debug(T&&x) {cerr<<x << '\n';}
    template<typename A, typename ...B>
    void _debug(A&&a, B&&...b) {cerr << a << ' '; _debug(b...);}
};

string debug_tool::ReplaceAll( string str, const string& from, const string& to ) {
    int start_pos = 0;
    while( (start_pos = str.find( from, start_pos)) != std::string::npos ) {
        str.replace( start_pos, from.length(), to);
        start_pos += to.length();
    }
    return str;
};


template<typename T>
string debug_tool::get_type( T val,bool short_name) {
    int status;
    string realname = abi::__cxa_demangle( typeid(val).name(), 0, 0, &status);

    if( short_name ) {
        realname = debug_tool::ReplaceAll( realname,  "std::", " ");
    }
    return realname;
}

/*------------------------------------------*/



string make_file( const string name, const int nth, const string subtitle = ".in") {
    /*
        for example ( a799_00.in ) => make_file( "a799", 0, ".in" )
        name => "a799"
        nth => "00" (you just need to input 0 )
        subtitle => ".in"
    */
    if( nth >= 100) {
        cerr << "your nth " << nth << " need to less than 100";
        exit(0);
    }
    string nth_name = string{ char( '0'+ (nth/10) ), char( '0' + (nth%10) )};
    return string( name + "_" +nth_name+subtitle );

}
void re_direct_std( const string file_name, bool cin_file = true, bool cout_file = true) {
    // if bool is true, it will redirect the std to file name
    if( cin_file ) freopen( file_name.c_str(), "r", stdin);
    if( cout_file ) freopen( file_name.c_str(), "w", stdout);
}
void origin_dircect_std() {
    //window
    freopen( "CON", "r", stdin );
    freopen( "CON", "w", stdout );

    //linux
    /*
    freopen( "/dev/console", "r", stdin );
    freopen( "/dev/console", "w", stdout );
    */
}

/* ----------------------------------------------------------------------- */
// if you don't want to researh, just modify after here
// use cerr to output the thing you want to watch
// or you can just use dstruct test_data;
debug_tool DEBUG;
test_data dataset;

void solve() {
    /* input your solution here */
}

int random_int(int a, int b) {
    uniform_int_distribution<int> dis(a, b);
    return dis(gen);
}
template<typename T>
void make_test_cases(T &&test_data ) {
    /* make your test cases here */
    const int N = test_data["N"].first;
    const int Q = test_data["Q"].first;

    cout << N << ' ' << Q << '\n';
    vector< int > rng(N+1);
    for( int i = 3; i <= N; ++i) {
        int f = random_int(0, i-2);
        int s = random_int(f, i-1);
        int t = random_int(s, i);
        cout << f << ' ' << s << ' ' << t << '\n';
    }
    if( Q == N-3 ) {
        for( int i = 4; i <= N; ++i) {
            cout << i << '\n';
        }
    }
    else {
        for( int i = 0; i < Q; ++i ) {
            cout << random_int(3, N) << '\n';
        }
    }

}

int main () {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    Time tm;
    tm.start();

    for( int _t = 0; _t < test_amount; ++_t) {
        const string IN_FILE = make_file( problem_id, _t, ".in");
        const string OUT_FILE = make_file( problem_id, _t, ".out");
        cerr << "start making " << _t << "-th test cases" << '\n';
        re_direct_std( IN_FILE, false, true);


        make_test_cases( dataset.get_data(_t) );

        cerr << "use " << tm.get_between() << "(sec) to complete " << _t << "-th test cases " <<'\n';

        origin_dircect_std();

        re_direct_std( IN_FILE, true, false);
        re_direct_std( OUT_FILE, false, true );
        solve();

        cerr << "use " << tm.get_between() << "(sec) to solve the " << _t << "-th test cases " << '\n';
        cerr << "------------------------------------\n";
    }

     cerr <<"all use : " << tm.get_all_time() <<" (sec) ";
    return 0;
}

 ```