Pagini recente » Cod sursa (job #1362093) | Cod sursa (job #1124255) | Cod sursa (job #733698) | Cod sursa (job #474103) | Cod sursa (job #1886035)
#include <vector>
#include <fstream>
using namespace std;
/**
`-.`'.-'
`-. .-'.
`-. -./\.- .-'
-. /_|\ .-
`-. `/____\' .-'.
`-. -./.-""-.\.- '
`-. /< (()) >\ .-'
- .`/__`-..-'__\' .-
,...`-./___|____|___\.-'.,.
,-' ,` . . ', `-,
,-' ________________ `-,
,'/____|_____|_____\
/ /__|_____|_____|___\
/ /|_____|_____|_____|_\
' /____|_____|_____|_____\
.' /__|_____|_____|_____|___\
,' /|_____|_____|_____|_____|_\
,,---''--...___...--'''--.. /../____|_____|_____|_____|_____\ ..--```--...___...--``---,,
'../__|_____|_____|_____|_____|___\
\ ) '.:/|_____|_____|_____|_____|_____|_\ ( /
)\ / ) ,':./____|_____|_____|_____|_____|_____\ ( \ /(
/ / ( ( /:../__|_____|_____|_____|_____|_____|___\ ) ) \ \
| | \ \ /.../|_____|_____|_____|_____|_____|_____|_\ / / | |
.-.\ \ \ \ '..:/____|_____|_____|_____|_____|_____|_____\ / / / /.-.
(= )\ `._.' | \:./ _ _ ___ ____ ____ _ _ _ _ _ _ _ __\ | `._.' /( =)
\ (_) ) \/ \ ( (_) /
\ `----' """""""""""""""""""""""""""""""""""""""""""""" `----' /
\ ____\__ __/____ /
\ (=\ \ / /-) /
\_)_\ \ / /_(_/
\ \ / /
) ) _ _ ( (
( (,-' `-..__ __..-' `-,) )
\_.-'' ``-..____ ____..-'' ``-._/
`-._ ``--...____...--'' _.-'
`-.._ _..-'
`-..__ CIOBY KNOWS ALL __..-'
``-..____ ____..-''
``--...____...--''
*/
class parser{
public:
parser() {}
parser(const char *file_name){
input_file.open(file_name,ios::in | ios::binary);
input_file.sync_with_stdio(false);
index=0;
input_file.read(buffer,SIZE);}///I/O iterators?
inline parser &operator >>(int &n){
for (;buffer[index]<'0' or buffer[index]>'9';inc());
n=0;
for (;'0'<=buffer[index] and buffer[index]<='9';inc())
n=10*n+buffer[index]-'0';
return *this;}
private:
fstream input_file;
static const int SIZE=0x400000;
char buffer[SIZE];
int index=0;
inline void inc(){
if(++index==SIZE)
index=0,input_file.read(buffer,SIZE);}
};
class writer{
public:
writer() {};
writer(const char *file_name){
output_file.open(file_name,ios::out | ios::binary);
output_file.sync_with_stdio(false);
index=0;}
inline writer &operator <<(int target){
aux=0;
n=target;
if (!n)
nr[aux++]='0';
for (;n;n/=10)
nr[aux++]=n%10+'0';
for(;aux;inc())
buffer[index]=nr[--aux];
return *this;}
inline writer &operator <<(const char *target){
aux=0;
while (target[aux])
buffer[index]=target[aux++],inc();
return *this;}
~writer(){
output_file.write(buffer,index);}///convert to stringstream?
private:
ofstream output_file;
static const int SIZE=0x100000;///optimal 0x200000
int index=0,aux,n;
char buffer[SIZE],nr[24];
inline void inc(){
if(++index==SIZE)
index=0,output_file.write(buffer,SIZE);}
};
parser f ("algsort.in");
writer t ("algsort.out");
vector <int> v;
int n;
int partition(int low,int high)
{ int mid=(low+high)>>1;
int pivot=v[mid];
int i=low-1;
int j=high+1;
LOOP:
do
++i;
while (v[i]<pivot);
do
--j;
while (v[j]>pivot);
if (i>=j)
return j;
swap(v[i],v[j]);
goto LOOP;
}
void quicksort(int low,int high)
{
int pivot;
if (low<high)
{
pivot=partition(low,high);
quicksort(low,pivot);
quicksort(pivot+1,high);
}
}
inline void citire()
{
f>>n;
v.resize(n);
for (int i=0; i<n; ++i)
f>>v[i];
}
inline void afisare()
{
for (auto i:v)
t<<i<<" ";
}
int main()
{
citire();
quicksort(0,n-1);
afisare();
return 0;
}